在JMeter中获取HTTP / 1.0 400错误请求

时间:2017-04-27 19:43:04

标签: jmeter

我使用JMeter记录了我的PHP / JSON站点。我试图运行录制的脚本并获得大多数采样器的错误消息。

我尝试将POST网址更改为"manufactureradmin/ticketsreportcontroller/getServiceAgency",但是我收到了错误的响应数据。

采样器请求

Thread Name: Thread Group 1-1 Sample Start: 2017-04-28 01:08:52 IST Load time: 106 Connect Time: 0 Latency: 106 Size in bytes: 493 Sent bytes:782 Headers size in bytes: 260 Body size in bytes: 233 Sample Count: 1 Error Count: 1 Data type ("text"|"bin"|""): text Response code: 400 Response message: Bad Request

Response headers: HTTP/1.0 400 Bad Request Date: Thu, 27 Apr 2017 19:38:52 GMT Server: Apache/2.4.25 (Amazon) PHP/7.0.14 X-Powered-By: PHP/7.0.14 0: HTTP/1.1 400 Bad Request Cache-Control: no-cache Content-Length: 233 Connection: close Content-Type: application/json

HTTPSampleResult fields: ContentType: application/json DataEncoding: null

请求

POST http://assist-qa.innothinkglobal.com/api/public/manufactureradmin/ticketsreportcontroller/getServiceAgency

POST数据:

Cookie数据: laravel_session=eyJpdiI6IjVjY3lkcmRSME83eGVWRmlCcHIrT2c9PSIsInZhbHVlIjoiM3FMeXRSQ1RndzU0ZmRnOFBpd21JN0FONU9TNlE4d1VYcCtoZjJvdGNBWmhoRUNcL2phU0tQR29yZXpKaHFmcDNlYUk0QUM0VlpHT3EyZ2JoeEJiNXB3PT0iLCJtYWMiOiI1ODgyMGEwMTE0ZTYyY2VhMGY4MWM5MDg4MzM3YmNlMzA3Mzc0YzEyNjFkNzUxY2YwNjA1ZGE0OTFhMmYzNmRhIn0%3D

Request Headers: Connection: keep-alive Referer: http://assist-qa.innothinkglobal.com/manufactureradmin/ Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 Accept: application/json, text/plain, */* Content-Type: application/x-www-form-urlencoded Content-Length: 0 Host: assist-qa.innothinkglobal.com

响应数据

{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the \"access token\" parameter."}

2 个答案:

答案 0 :(得分:1)

您需要将HTTP Header Manager添加到Test Plan并将其配置为发送Content-Type,其值为 application/json

查看您的采样器结果,您发送的请求为application/x-www-form-urlencoded,我的期望是这是您的服务器无法正确解析请求的原因。

有关配置JMeter以将请求发送到API端点的详细信息,请参阅Testing SOAP/REST Web Services Using JMeter文章。

答案 1 :(得分:0)

OAuth基本上是一种获取令牌的方式。如果您要对启用OAuth的应用程序进行负载测试,则需要执行以下操作:

请求临时访问令牌 授权访问令牌 将临时访问令牌更改为永久性 您可以手动执行上述步骤,通过嗅探器捕获永久访问令牌,并将其作为单独的HTTP Request参数添加到您的请求中。如果您在测试中重复使用有限数量的用户登录,则可以为您提供帮助。

但是,如果您需要测试端到端流程(假设通过JMeter获取令牌流程),则需要考虑OAuth Sampler Plugin

所以基本上你需要做以下其中一项:

手动三步OAuth登录和捕获令牌流程,然后添加令牌作为每个虚拟用户的HTTP请求参数 通过JMeter OAuth采样器自动执行OAuth登录过程 如果登录/用户数量有限,则选项1可能更好