是的,你可以在运行时传递它们。事实上,几乎和你输入的一样。这将是你的API接口类,名叫说SecretApiInterface.java
public interface SecretApiInterface {
@GET("/secret_things")
SecretThing.List getSecretThings(@Header("Authorization") String token)
}
然后在请求中传递的参数为这个接口,类似的规定:(该文件将是例如SecretThingRequest。 java的)
public class SecretThingRequest extends RetrofitSpiceRequest<SecretThing.List, SecretApiInteface>{
private String token;
public SecretThingRequest(String token) {
super(SecretThing.List.class, SecretApiInterface.class);
this.token = token;
}
@Override
public SecretThing.List loadDataFromNetwork() {
SecretApiInterface service = getService();
return service.getSecretThings(Somehow.Magically.getToken());
}
}
凡Somehow.Magically.getToken()
是一个方法调用返回一个令牌,它是由你在何处以及如何定义它。
您当然可以在接口实现中有多个@Header("Blah") String blah
注释,就像您的情况一样!
我感到十分困惑过,the documentation明确表示,它取代头,但它不!
它实际上是在增加与@Headers("hardcoded_string_of_liited_use")
注释
希望这有助于;)
你有没有想过这个?我需要在标题中传递令牌 – theSociableme
我也在寻找解决方案,从文档听起来像[@Headers()](http://square.github.io/retrofit/javadoc/retrofit/ http/Header.html)方法_adds fields_中的标注逐个标题,但仅支持文字。 和[@Header(“参数”)字符串字符串](http://square.github.io/retrofit/javadoc/retrofit/http/Header。html)参数注释_replaces_标题与提供的值。 – nana
同样在这里,无法找到如何使用改造时处理会话。 – feresr