栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在JMeter中使用JSON BODY配置HTTP请求方法GET?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在JMeter中使用JSON BODY配置HTTP请求方法GET?

实际上,Apache HttpComponents不支持通过HTTP
GET请求发送请求正文,因此在JMeter中,您应该能够使用JSR223
Sampler
和以下代码(假定使用Groovy语言)通过JSON正文发送GET请求:

import org.apache.http.HttpResponseimport org.apache.http.client.methods.HttpEntityEnclosingRequestbaseimport org.apache.http.entity.StringEntityimport org.apache.http.impl.client.CloseableHttpClientimport org.apache.http.impl.client.HttpClientBuilderimport org.apache.http.util.EntityUtilspublic  class HttpGetWithBody extends HttpEntityEnclosingRequestbase {    public final static String METHOD_NAME = "GET";    @Override    public String getMethod() {        return METHOD_NAME;    }}def client = HttpClientBuilder.create().build();def getRequest = new HttpGetWithBody();getRequest.setURI(new URL("http://example.com").toURI());def json = "{"employees":[n" +        "    {"firstName":"John", "lastName":"Doe"},n" +        "    {"firstName":"Anna", "lastName":"Smith"},n" +        "    {"firstName":"Peter", "lastName":"Jones"}n" +        "]}";def body = new StringEntity(json, "application/json", "UTF-8");getRequest.addHeader("Content-Type", "application/json");getRequest.setEntity(body);def response = client.execute(getRequest);def result = EntityUtils.toString(response.getEntity());log.info(result);

请参见Beanshell与JSR223与Java
JMeter脚本:您一直在等待的性能下降!
有关使用JSR223测试元素和groovy语言以及脚本最佳实践的更多信息的文章。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/370551.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号