【发布时间】:2015-06-15 23:12:48
【问题描述】:
HttpClient httpClient = new DefaultHttpClient();
try {
HttpPost request = new HttpPost(strUrl);
StringEntity params =new StringEntity(json.toString(), "UTF-8");
//request.addHeader("content-type", "application/x-www-form-urlencoded");
params.setContentType("application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
HttpEntity entity1 = response.getEntity();
is = entity1.getContent();
int resopnceStatus = response.getStatusLine().getStatusCode();
AppLog.logString(TAG + "get data resopnceStatus: " + resopnceStatus);
if (resopnceStatus != 200) {
return "Invalid";
}
}catch (IllegalArgumentException timeout) {
timeout.printStackTrace();
return "Invalid";
} catch (SocketTimeoutException timeout) {
timeout.printStackTrace();
return "Invalid";
} catch (Exception e) {
e.printStackTrace();
return "Invalid";
}
String response = "";
String s = "";
try {
BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
while ((s = buffer.readLine()) != null) {
response += s;
}
} catch (Exception e) {
AppLog.logString(TAG + "get data Error in Buffered: " + e.toString());
e.printStackTrace();
}
AppLog.logString(TAG + "get data Return Data is: " + response);
在正常的 post rest web 服务中使用上面的代码可以正常工作,但在 PATCH api 中它无法正常工作,导致未找到响应状态 400 meance 页面,但在 Chrome rest 客户端中可以正常工作。 PATCH有什么解决办法吗?
【问题讨论】:
-
你能在
in PATCH api its not working分享更多细节 -
@nikis 什么??在 Chrome 休息客户端工作正常时,它在 android 中给了我错误
-
太棒了。你在谈论错误而不发布它。
-
@nikis 它给出的响应码 400 意思是找不到页面,但这并不是调用 PATCH 方法的正确方法,但我不知道
-
code
400并不代表没有找到该页面,而是表示请求错误。您可以从比较从Android和Chrome发送的请求开始。