JMeter:如何使用 BeanShell 发送 HTTP GET 请求

JMeter: How to send HTTP GET request using BeanShell

我正在研究 JMeter,想使用 BeanShell 采样器向 http://google.com 发出 HTTP GET 请求,而不使用 HTTP 请求采样器。可能吗?如果可以,我该怎么做?

提前致谢!

这是可能的,但我不明白你为什么需要这个。

此外 starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting mainly because Groovy has much better performance comparing to Beanshell, in addition Groovy is more modern language which supports all the latest Java features and provides a lot of enhancements on top of it, see 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()));

更多信息: