簡體   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