【发布时间】:2018-02-01 19:27:49
【问题描述】:
我想在 Android 应用程序中使用两个标头发出请求,第一个标头有一个参数。我试过这个:
@Headers("Content-Type: application/json")
@GET("/ebuzon/client/show")
Call<Client> showClient(@Header("Authorization") String token);
call = api.showClient(" Bearer " +MySharedUser.getInstance().getToken());
401 未经授权
已编辑:这应该可行,请参阅@Robert 答案。我的问题也是更新令牌
@GET("/ebuzon/client/show")
Call<Client> showClient(@Header("Authorization") String token,
@Header("Content-Type") String appJson);
call = api.showClient(" Bearer" +MySharedUser.getInstance().getToken(), "application/json");
401 未经授权
@Headers({"Authorization: Bearer {token}","Content-Type: application/json"})
@GET("/ebuzon/client/show")
Call<Client> showClient(@Path("token") String token);
IllegalArgumentException:URL“/ebuzon/client/show”不包含“{token}”。 (参数#1)
我在这样的角度上做同样的事情,它正在工作
var obj = this.http.get("/ebuzon/client/show",
{headers: new HttpHeaders().set("Authorization", " Bearer "+ this.token).append("Content-Type","application/json")})
.map(res => {
console.log(res);
return res
})
.catch(err => {
console.log(err);
return err;
})
return obj;
感谢您的帮助。
【问题讨论】: