简体   繁体   中英

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 127.0.0.1:8000/api-token-auth/ username='admin' password='whatever'

I am trying to do this with Retrofit:

@Headers("username=\'admin\' password=\'whatever\'")
@POST("/api-token-auth")
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?

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM