首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >HTTP或HTTP或HTTP,Android

HTTP或HTTP或HTTP,Android
EN

Stack Overflow用户
提问于 2014-12-22 20:29:30
回答 1查看 221关注 0票数 0

这是我第一次尝试使用web。我正在尝试为显示名称https://github.com/Privo/PRIVO-Hub/wiki/Web-Services-API-Reference#update-user-display-name实现这个PRIVO。正如您所看到的,没有太多的解释或代码示例。

我要做的是使用HTTP接收一个有效的响应,这表明名称是正确的格式,然后我应该将这个显示名称保存在我们的google服务器上。我只需要上半场的帮助。稍后我将研究如何保存到云服务器上。

我面临的问题是,我不确定这是否是如何使用HTTP,我也不能100%确定我不应该使用POST或PUT。到目前为止,这就是我所拥有的,请让我知道我做错了什么。

代码语言:javascript
复制
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);
   }
}

}));   

根据上述代码,我将得到以下响应

{“消息”:“未找到对象”、"validationErrors":[]、"responseTimestamp":1419278367177、"totalCount":-1、“状态”:“失败”、"resultCount":-1、“实体”:null}

这种反应意味着什么?它在onFailure(int statusCode,String apiName,JSONObject errorResponse)上失败,错误代码为404。

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-22 20:33:41

您应该使用API文档中说应该使用的任何方法。在这种情况下,既不是GET,也不是POST,而是PUT!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27609957

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档