【发布时间】:2014-12-23 05:04:58
【问题描述】:
这是我第一次尝试使用 Web API。我正在尝试为显示名称https://github.com/Privo/PRIVO-Hub/wiki/Web-Services-API-Reference#update-user-display-name 实现此 PRIVO API。如您所见,没有太多的解释或代码示例。
我想要做的是使用 HTTP GET 来接收表明名称格式正确的有效响应,然后我应该将此显示名称保存在我们的谷歌服务器上。我只需要前半部分的帮助。稍后我会弄清楚如何保存到云服务器上。
我面临的问题是我不确定这是否是使用 HTTP GET 的方法,我也不是 100% 确定我也不应该使用 POST 或 PUT。这是我到目前为止所拥有的,请让我知道我做错了什么。
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.get(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);
}
}
}));
我在上述代码的结果中得到以下响应
{"message":"找不到对象","validationErrors":[],"responseTimestamp":1419278367177,"totalCount":-1,"status":"failed","resultCount":-1,"实体":null}
这个响应是什么意思?它在 onFailure(int statusCode, String apiName, JSONObject errorResponse) 上失败,错误代码为 404
提前致谢!
【问题讨论】:
标签: android http asp.net-web-api