- Processing and handling JSON responses using BSF post processors
- Using BSF Assertion to fail samples based on JSON response
- Changing sample label/name at runtime
NOTE: I successfuly used this technique for webservices exposed by the Jersey library as well as ASP.NET asmx webservices
It's quite simple. Assuming you need to send POST request to the /login URI passing two parameters: email and password encoded as JSON, like this:
{ email: 'myemail@email.com', password: 'mypassword' }
Just follow two basic steps:
Step 1 - Setting the "ContentType" http header attribute to "application/json"
- Add an HTTP Header Manager to your test plan;
- Add a new attribute: set name to "Content-Type" and value to "application/json"
Step 2 - Setting the JSON object as an unnamed http request parameter
- Add a HttpRequest sampler
- Add a new parameter, leave the name blank and set the value to the JSON string: { 'email': 'myemail@email.com', 'password': 'mypassword' }
And last but not least: you can use variables and properties as you wish in the JSON string. Suppose you have a CSV Data Set Config which defines to external variables: email e pwd. You could use them in your sampler like this:
{ email: '${email}', password: '${pwd}' }
Thanks for these tips!
ResponderExcluirLuckily since the time of your post, the JMeter community has addressed this issue, and from the help file we now have:
Since JMeter 2.6, you have the option to switch to Post Body when a request has only unnamed parameters (or no parameters at all). This option is useful in the following cases (amongst others):
GWT RPC HTTP Request
JSON REST HTTP Request
XML REST HTTP Request
SOAP HTTP Request
Hope this helps anyone who finds this post.
You are right!
ExcluirI'm currently using this feature in 2.9!
Thanks for the heads up!
Fabio, this does work. Many thanks!
ResponderExcluirHi Fabio,
ResponderExcluirI am working on RESTful Services and I am using a huge json file in my RAW POST body and every time it takes very long time to come out of the node. The jmeter becomes very slow. Do we have any alternative to send the body which containes a json requests in a file.
I use HTTP Request Sampler for REST Services.
Any help is highly appreciated.
Does your JSON has variable placeholders? Or is it static?
Excluir