关于http的delete请求返回结果,请求返回只有header部分,不存在body部分的问题

错误描述信息:

HTTP/1.1 200 OK [Server: nginx/1.14.0, Date: Thu, 28 Jun 2018 09:49:02 GMT, Content-Type: application/json; charset=utf-8, Content-Length: 34, Connection: keep-alive, Cache-Control: no-cache, Pragma: no-cache, Expires: -1, X-AspNet-Version: 4.0.30319, X-Powered-By: ASP.NET]

代码:
{完整的HttpDelete请求}
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public static String sendDelete(String url, String Json) {
HttpResponse response = null;
String result = null;
try {
HttpEntity entity = new StringEntity(Json);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpDeleteWithBody httpDeleteWithBody = new HttpDeleteWithBody(url);
httpDeleteWithBody.setHeader("Content-Type", "application/json; charset=UTF-8");
httpDeleteWithBody.setEntity(entity);
response = httpClient.execute(httpDeleteWithBody);
//关键代码
result = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
e.printStackTrace();
}
return result;
}


参考所给引用内容,未直接提及JMeter中HTTP DELETE请求体的编写方法。过可以结合HTTP协议及JMeter相关操作思路来推测。 HTTP DELETE请求HTTP协议中常用的请求方法之一,用于请求服务器删除指定的资源[^1]。在JMeter中编写HTTP DELETE请求体,可按以下思路: 1. **新建线程组**:如同使用JMeter写其他HTTP请求一样,先新建线程组,参数可使用默认值。这是JMeter脚本编写的基础步骤,为后续的请求操作提供执行环境[^2]。 2. **添加HTTP请求**:在该线程组下添加HTTP请求请求方法选择“DELETE”。 3. **配置请求信息**: - **请求URL**:填写要删除资源的完整URL。 - **请求头设置**:可参考HTTP信息请求头管理的配置方法,添加必要的请求头信息。例如,设置`Content-Type`等。若要告诉服务器客户端的相关信息,可设置`User-Agent`;若要表明请求来源,可设置`referer`等。添加请求头可通过键值对的形式,在代码中可调用`addHeader(String name, String value)`在请求对象中添加相应请求头[^2][^3]。 - **请求体**:DELETE请求通常需要请求体,但如果服务器端需要额外信息来确定要删除的资源,可以在请求体中添加。若要发送JSON格式的数据,可在“Body Data”中输入JSON数据,并确保“Content-Type”设置为`application/json`。 示例代码(假设用Java代码模拟添加请求头): ```java import org.apache.http.client.methods.HttpDelete; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; public class HttpDeleteExample { public static void main(String[] args) { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpDelete httpDelete = new HttpDelete("https://example.com/api/resource/1"); // 添加请求httpDelete.addHeader("Content-Type", "application/json"); httpDelete.addHeader("User-Agent", "JMeter/5.0"); // 后续可执行请求等操作 } } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值