繁体   English   中英

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

[英]JMeter: How to send HTTP GET request using BeanShell

I am studying JMeter and want to make a HTTP GET request to http://google.com using BeanShell Sampler without using HTTP Request Sampler. 可能吗? 如果是这样,我该怎么做?

提前致谢!

有可能但是我看不出你为什么需要这个。

Moreover 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其中,有关更多详细信息,请参阅Apache Groovy - 为什么以及如何使用它一文。

示例代码:

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()));

更多信息:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM