[英]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. 我正在尝试使用Django发送HTTP请求,该请求在标头中包含用户名和密码,以便检索令牌。
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: 我正在尝试通过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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.