的-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);
}
非常感謝你! –