我想在主体(不是表单)中执行带有 xml 的 HTTP DELETE 请求。如何执行此 HTTP DELETE 请求?
我试过 HttpURLConnection
但是there are some limitations with it .
我尝试使用 apache 的 HttpClient
也。但是我不知道如何发送没有application/x-www-form-urlencoded
结构的xml。
最佳答案
此代码将实现:
try {
HttpEntity entity = new StringEntity(jsonArray.toString());
HttpClient httpClient = new DefaultHttpClient();
HttpDeleteWithBody httpDeleteWithBody = new HttpDeleteWithBody("http://10.17.1.72:8080/contacts");
httpDeleteWithBody.setEntity(entity);
HttpResponse response = httpClient.execute(httpDeleteWithBody);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
要访问响应,您只需执行以下操作:response.getStatusLine();
这里是 HttpDeleteWithBody 类定义:HttpDeleteWithBody
关于android - 如何执行带正文的 HTTP DELETE 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15097104/