JMeter: How to send parameters with PATCH method?

2019-08-08 15:56发布

问题:

My JMeter version is the latest version 2.13. I would like to add an HTTP request to test my API, and the method is either PATCH or PUT.

In Postman, I can test the API and succeed using the PATCH method with some URL parameters.

For example:

URL: https://example.com/user/account
URL parameters: email ----> example@example.com
URL parameters: password ----> 12345678
Method: PATCH

This works in Postman/Paw but in JMeter I setup an HTTP request, add the parameters, and it fails.

How I can setup a working PATCH/PUT request with parameters in JMeter?

回答1:

I solved the problem with a temporary solution by adding the parameters to the HTTP request:

https://example.com/user/account?email=example%40example.com&password=12345678

and then delete the parameter in the HTTP request. It works now.

I hope I can find a formal solution to solve this.



回答2:

It seems that JMeter (at least as of version 2.13 r1665067) doesn't support passing parameters for PATCH requests using the "Parameters" table.

However, you can still pass parameters using the following workarounds:

  • If you want to have your parameters in the query string (GET-like), you can just append them to the path: /foo/bar?param1=2&param2=21.
  • If you want to have your parameters in the body (POST-like), you can switch to the "Body data" tab in the "HTTP Request" section and provide your encoded parameters there like this: param1=2&param2=21. Be sure to properly URL encode all parameters. Additionally you have to add a line to request header in the "HTTP Header Manager" section. Add the header Content-Type with the value application/x-www-form-urlencoded.


回答3:

Just to complete/improve @Lukas answer, if you are importing the test parameters from a CSV file, you need to format the HTTP Request Path as follows:

/foo/bar?param1=${csv_param1_name}&param2=${csv_param2_name}

This needs to be done because, at least for PATCH requests, the parameters table is ignored.

This applies also to JMeter v4.0 r1823414.



回答4:

Jmeter uses the body data to fill with your data but no need a header, you can pass your data to backend. enter image description here

But I use httpServletRequest to get the parameter and it is empty, I don't know why...