TAGS :Viewed: 7 - Published at: a few seconds ago

[ How to Properly Format RetroFit Header for Django ]

I am trying to send an HTTP request using Django that includes a username and password in the header in order to retrieve a token.

On my computer terminal I do the following command and it works properly:

http POST username='admin' password='whatever'

I am trying to do this with Retrofit:

@Headers("username=\'admin\' password=\'whatever\'")
Call<TokenJSON> getToken();

However I am presented with the error:

@Headers value must be in the form "Name: Value"

Is there a correct way to format this header?

Answer 1

If the values are dynamic you can use:

Call<TokenJSON> getToken(@Header("username") String var1, @Header("password") String var2);

Or if they are static you can use:

@Headers({"username: Bar", "password: Pong"})
Call<TokenJSON> getToken();