gpt4 book ai didi

android - 如何执行带正文的 HTTP DELETE 请求?

转载 作者:可可西里 更新时间:2023-11-01 16:56:35 25 4
gpt4 key购买 nike

我想在主体(不是表单)中执行带有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com