How to read a web page using Bean shell in JMeter?

て烟熏妆下的殇ゞ 提交于 2019-12-11 12:37:37

问题


Use Bean Shell sampler to hit simple Google search, do I need a code for this?


回答1:


It is better to use HTTP Request sampler, however if for some reason you need to do it in Beanshell here is the example script:

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://google.com");
HttpResponse response = httpclient.execute(httpGet);
String responseString = EntityUtils.toString(response.getEntity());
String responseCode = String.valueOf(response.getStatusLine().getStatusCode());
String responseCode = String.valueOf(response.getStatusLine().getStatusCode());
return responseString;

See the following reference material:

  • HttpClient Quick Start
  • How to Use BeanShell: JMeter's Favorite Built-in Component


来源:https://stackoverflow.com/questions/36276916/how-to-read-a-web-page-using-bean-shell-in-jmeter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!