如何使用body执行HTTP DELETE请求? [英] How can I perform a HTTP DELETE request with body?
本文介绍了如何使用body执行HTTP DELETE请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用正文(而非表单)中的xml执行HTTP DELETE请求.如何执行此HTTP DELETE请求?
I want to perform a HTTP DELETE request with a xml in the body (not a form). How can I perform this HTTP DELETE request?
我尝试使用 HttpURLConnection
,但是我尝试使用apache的 HttpClient
也是.但是我不知道如何在没有application/x-www-form-urlencoded
结构的情况下发送xml.
I tried with the apache's HttpClient
too. But I don't know how to send the xml without the structure of application/x-www-form-urlencoded
.
推荐答案
此代码将使其成功:
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();
To access the response you can simply do: response.getStatusLine();
这是HttpDeleteWithBody类的定义: HttpDeleteWithBody
And here is the HttpDeleteWithBody class definition: HttpDeleteWithBody
这篇关于如何使用body执行HTTP DELETE请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文