【发布时间】:2020-08-24 16:45:24
【问题描述】:
我正在研究 JMeter,想使用 BeanShell Sampler 向 http://google.com 发出 HTTP GET 请求,而不使用 HTTP Request Sampler。可能吗?如果是这样,我该怎么做?
提前致谢!
【问题讨论】:
标签: http jmeter request jmeter-5.0
我正在研究 JMeter,想使用 BeanShell Sampler 向 http://google.com 发出 HTTP GET 请求,而不使用 HTTP Request Sampler。可能吗?如果是这样,我该怎么做?
提前致谢!
【问题讨论】:
标签: http jmeter request jmeter-5.0
有可能,但是我不明白你为什么需要这个。
此外,starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language 用于脚本编写,主要是因为与 Beanshell 相比,Groovy 具有更好的性能,此外,Groovy 是更现代的语言,它支持所有最新的 Java 功能并在其之上提供a lot of enhancements,请参阅Apache Groovy - Why and How You Should Use It 文章更多细节。
示例代码:
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.util.EntityUtils
HttpClient client = HttpClientBuilder.create().build();
HttpGet get = new HttpGet("http://google.com");
HttpResponse response = client.execute(get);
SampleResult.setResponseData(EntityUtils.toByteArray(response.getEntity()));
更多信息:
【讨论】: