【发布时间】:2014-12-23 19:40:03
【问题描述】:
我需要一些帮助来纠正我使用以下 API 的方法 > https://github.com/Privo/PRIVO-Hub/wiki/Web-Services-API-Reference#update-user-display-name。
我不确定如何使用 LoopJ AndroidAsyncHttp PUT 发送 JSON 对象进行更新。我收到以下错误响应
{"message":"Error: null","validationErrors":[]."responseTimestamp":141936124612,"totalCount":-1,"status":"failed","resultCount":-1,"实体":null}
我怎么做错了?
AsyncHttpClient client = null;
String authorizationHeader = "token_type", "" + " " + "access_token", "");
client.addHeader("Authorization", authorizationHeader);
client.addHeader("Content-type", "application/json");
client.addHeader("Accept", "application/json");
String requestBody = "displayName=" + "hardcodedDisplayName";
String requestURL = "https://privohub.privo.com/api/" + "account/public/saveDisplayName?" + requestBody;
client.put(requestURL, new ResponseHandler(myClass.this, "displayName", new OnResponseHandler() {
@Override
public void onSuccess(int statusCode, String apiName, JSONObject response) {
if (statusCode == 200) {
Log.i(TAG, "Seems to be working")
}
}
@Override
public void onFailure(int statusCode, String apiName, String responseMessage) {
Log.i(TAG, "Fail: " + responseMessage);
}
@Override
public void onFailure(int statusCode, String apiName, JASONArray errorResponse) {
Log.i(TAG, "Fail: " + errorResponse);
}
@Override
public void onFailure(int statusCode, String apiName, JSONObject errorResponse) {
if (errorResponse != null) {
Log.i(TAG, "Fail: " + errorResponse);
}
}
}));
【问题讨论】:
-
对在 android 中选择客户端感到好奇...android-developers.blogspot.com/2011/09/… .. 你是从哪里想到 android 上的 java httpclient 的?我认为(loopj、volley、okhttp、apache 的 android 客户端)可能更适合??
-
我正在尝试使用 loopj。 grepcode.com/file/repo1.maven.org/maven2/com.loopj.android/…。问题是,这是我第一次尝试。我认为我的 PUT 参数可能不正确。
标签: android http asp.net-web-api android-async-http