使用Bean Shell sampler命中简单的Google search,我需要一个代码吗?
答案 0 :(得分:1)
最好使用HTTP Request采样器,但是如果出于某种原因需要在Beanshell中执行此操作,则示例脚本为:
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;
请参阅以下参考资料: