为什么我在Retrofit Post Operation中获取属性值必须是常量错误?

时间:2018-04-18 14:09:46

标签: java android retrofit

我正在尝试将令牌添加到 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);

**

1 个答案:

答案 0 :(得分:0)

您可以改用

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);
相关问题