的-d
参数卷曲增加POST参数。在这种情况下,grant_type
和code
。我们可以使用@Field
注释对每个进行改进编码。
public interface AuthApi {
@FormUrlEncoded
@POST("/admin/oauth/token")
void getImage(@Header("Authorization") String authorization,
@Field(("grant_type"))String grantType,
@Field("code") String code,
Callback<Object> callback);
}
如果授权字段正在使用@Header
解决方案给你的链接问题。
使用会是什么样 -
RestAdapter authAdapter = new RestAdapter.Builder().setEndpoint("http://example.com/").build();
AuthApi authApi = authAdapter.create(AuthApi.class);
try {
final String auth = "Basic " + getBase64String(":");
authApi.getImage(auth, "authorization_code", "", new Callback<Object>() {
@Override
public void success(Object o, Response response) {
// handle success
}
@Override
public void failure(RetrofitError error) {
// handle failure
}
});
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
其中getBase64String
是从你的链接答案的辅助方法。复制下面的完整性 -
public static String getBase64String(String value) throws UnsupportedEncodingException {
return Base64.encodeToString(value.getBytes("UTF-8"), Base64.NO_WRAP);
}
非常感谢你! –