Skip to content Skip to sidebar Skip to footer

Add Headers To Request Using Retrofit 2

I'm trying to send requests with authentication headers, but it seems that the server cannot identify the client. I used this tutorial, and implemented an interceptor as follows:

Solution 1:

@Headers("Accept: application/json")
@FormUrlEncoded@POST("sendWalletMoney")
Call<WalletResponse> sendWalletMoney(@Field("sender") String sender,
                                     @Field("receiver") String receiver,
                                     @Field("amount") String amount,
                                     @Field("trnsx_type") String trnsx_type,
                                     @Field("currency") String currency,
                                     @Field("module_name") String module_name);

Solution 2:

Looks like a server issue. You can try adding the headers he talked about in your interceptor.

builder.addHeader("Accept", "*/*").addHeader("accept-encoding",  "gzip, deflate")

But the cookie should be used on the web to keep track of the current session. Shouldn't be needed on the API.

Post a Comment for "Add Headers To Request Using Retrofit 2"