是否可以让Jmeter将一组HTTP请求响应的最终结果返回到Webhook URL?
例如:我有一个使用多个HTTP请求/响应创建的迷你旅程。使用getResponsesData和PostProcessor Groovy检索最终的HTTP请求响应主体,我确定测试是通过还是失败。我想将其与webhook url集成在一起,该怎么做?
答案 0 :(得分:1)
JMeter基于Apache HttpComponents构建,因此您可以使用Apache HttpClient从Groovy代码直接调用HTTP请求,例如:
import org.apache.http.client.methods.HttpGet
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
def httpClient = HttpClients.createDefault()
def httpGet = new HttpGet("http://example.com")
def response = httpClient.execute(httpGet)
//do what you need with the response, i.e. print it to jmeter.log
log.info(EntityUtils.toString(response.getEntity()))
response.close()
httpClient.close()
查看Sending HTTP and HTTPS Requests Using Groovy in JMeter,以获取全面的信息和高级方案示例