【问题标题】:Why I get Attribute value must be constant error in Retrofit Post Operation?为什么我在 Retrofit Post Operation 中得到 Attribute value must be constant 错误?
【发布时间】:2018-09-28 19:49:34
【问题描述】:

我正在尝试将 token 添加到 HTTP @POST 中的 url 字符串,但我得到了

属性值必须是常量错误

。我想不通为什么?我正在使用改造 2。

**

public interface API { 

  static final String url = ("/secure/frrest/oauth2/token/"+ Prefs.getSmartPassAccessToken(App.getContext()) + "?_action=revokeTokens");


  @FormUrlEncoded
  @POST(url)
    void smartpassnonpersistentlogout(@Header("Content-Type") String content_type,
            @Field("client_id") String client_id,
            Callback<SmartPassResponse> callback);

**

【问题讨论】:

标签: java android retrofit


【解决方案1】:

你可以改用这个

public interface API { 
@FormUrlEncoded
@POST("/secure/frrest/oauth2/token/{token}")
void smartpassnonpersistentlogout(@Path("token") String token,@Query("_action")String _action,@Header("Content-Type") String content_type,
            @Field("client_id") String client_id,
            Callback<SmartPassResponse> callback);

那么就可以这样调用了

String token=Prefs.getSmartPassAccessToken(pass_context);
yourinterface.smartpassnonpersistentlogout(token,"revokeTokens",...add remaining params);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多