Reputation: 618
I have a rest web-service which accepts JSON post data but for requesting any API url, we need to pass access_token
.
So my post data is a JSON data and access_token
is passed as query string.
Problem:
As per my exploration i have not found any way to send request which can have JSON post data and also accepts Query String from the HTTP-URL-REWRITING in JMeter.
Actual Request:
POST http://<domain>/webapp/service/document/save
POST data: { node = '1'}token_XXXXXX
[no cookies]
Request Headers: Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 980 Host: localhost User-Agent: Apache-HttpClient/4.2.3 (java 1.5)
Below is the expected request data.
Expected Request:
POST http://<domain>/webapp/service/document/save?access_token=token_XXXXXX
POST data: { node = '1'}
[no cookies]
Request Headers: Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 980 Host: localhost User-Agent: Apache-HttpClient/4.2.3 (java 1.5)
How should i configure it in JMeter?
Upvotes: 1
Views: 8385
Reputation: 34566
In path field, add access_token like this:
And use raw post body for the JSON content.
Upvotes: 1
Reputation: 618
I just found the solution for this .
Instead of using Header Manager , I have used BeanShell preprocessor where I just removed the argument from the aeguments availble in Beanshell preprocessor and addded the QueryString to path of the request using setPath() method available in BeanShell Preprocessor .
Arguments arguments = sampler.getArguments();
String access_token = sampler.getArguments().getArgumentsAsMap().get("access_token");
arguments.removeArgument("access_token");
String path = sampler.getUrl() + "?access_token=" + access_token;
sampler.setPath(path);
This code solved my problem. Alternate is HeaderManager. Already Answered by @PMD UBIK-INGENIERIE
Upvotes: 0