实际上,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语言以及脚本最佳实践的更多信息的文章。



