通过 Jmeter 发送 restful 请求
send restful request by Jmeter
我有一个 restful 请求,我需要使用 Jmeter 将它发送到网络服务。
这是我的请求:
{"type":"CustomerProfileReqModel","messageCode":"GetCustRq","messageVersion":"V1.0","language":"en-gb","recieverCode":"newone","customerModel":{"userName":"load24","password":"P@ssw0rd","categoryCode":"NORM"},"uiCacheVersion":"3e096b72-ed40-4f8a-aad3-9ed52a4aa8ba"}
这是我在 JMeter 中创建的:
线程组
SOAP/XML-RPC请求
URL:http://localhost:9000/MyFawryWeb/rest/MFServlet/service
当我 运行 时出现以下错误:
org.apache.commons.httpclient.NoHttpResponseException: The server 11.92.0.91 failed to respond
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1976)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
at org.apache.jmeter.protocol.http.sampler.SoapSampler.sample(SoapSampler.java:271)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1088)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1077)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:428)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.lang.Thread.run(Unknown Source)
您需要使用 HTTP Request Sampler 发送 REST 请求,JSON 负载需要进入 "Body Data" 选项卡,如:
- 我相信您还应该添加一个 HTTP Header Manager and configure it to send Content-Type header,其值为
application/json
- 添加 View Results Tree 侦听器以检查请求和响应的详细信息以及 运行 您的请求(当涉及到 运行ning 负载测试时,不要忘记将其删除用户)
有关详细信息和详细说明,请参阅 REST API Testing - How to Do it Right。
我有一个 restful 请求,我需要使用 Jmeter 将它发送到网络服务。 这是我的请求:
{"type":"CustomerProfileReqModel","messageCode":"GetCustRq","messageVersion":"V1.0","language":"en-gb","recieverCode":"newone","customerModel":{"userName":"load24","password":"P@ssw0rd","categoryCode":"NORM"},"uiCacheVersion":"3e096b72-ed40-4f8a-aad3-9ed52a4aa8ba"}
这是我在 JMeter 中创建的:
线程组 SOAP/XML-RPC请求 URL:http://localhost:9000/MyFawryWeb/rest/MFServlet/service
当我 运行 时出现以下错误:
org.apache.commons.httpclient.NoHttpResponseException: The server 11.92.0.91 failed to respond at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1976) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at org.apache.jmeter.protocol.http.sampler.SoapSampler.sample(SoapSampler.java:271) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1088) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1077) at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:428) at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) at java.lang.Thread.run(Unknown Source)
您需要使用 HTTP Request Sampler 发送 REST 请求,JSON 负载需要进入 "Body Data" 选项卡,如:
- 我相信您还应该添加一个 HTTP Header Manager and configure it to send Content-Type header,其值为
application/json
- 添加 View Results Tree 侦听器以检查请求和响应的详细信息以及 运行 您的请求(当涉及到 运行ning 负载测试时,不要忘记将其删除用户)
有关详细信息和详细说明,请参阅 REST API Testing - How to Do it Right。