问题描述
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有什么解决方案吗?
Using above code in normal post rest web service it's working fine but in PATCH api its not working giving responce status 400 meance page not found but it's working fine in Chrome rest client.Any solution for PATCH?
推荐答案
下载httpclient-4.2.jar文件.
Download httpclient-4.2.jar file.
导入以下文件
import org.apache.http.message.AbstractHttpMessage;import org.apache.http.client.methods.HttpRequestBase;import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;import org.apache.http.client.methods.HttpPatch;
import org.apache.http.message.AbstractHttpMessage;import org.apache.http.client.methods.HttpRequestBase;import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;import org.apache.http.client.methods.HttpPatch;
放入
HttpPatch request = new HttpPatch(strUrl);
装有
HttpPost request = new HttpPost(strUrl);
这篇关于使用PATCH方法的Android REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!