What is the difference between parameters and body data in HTTP request in Jmeter? - jmeter

i am unable to provide request to the server in json format using parameters so please can anyone explain me about it?
I sent this request from Bodydata extracting data from CSV:
POST data:
{
"password":"login",
"username":"568592"
}
but when i used parameters for extracting data from CSV:
POST data:
password=login&username=568592
How can i send json format request using parameters?

There should be no difference given you properly pass your JSON via "Parameters" section.
If you want to use "Parameters" - just put your JSON payload into "Value" section of the 1st parameter like:
If you want to use "Body Data" - put your JSON Payload there (don't forget to remove everything from the "Parameters" section)
Don't forget to add HTTP Header Manager to send Content-Type header with the value of application/json

Related

I want to send the data that has been url encoding in Jmeter

I want to send a data that has been encryption.
So, I used JSR223 Sampler.
---skip---
def encrypted = Crypto.encrypt("AES/CBC/PKCS5Padding", "{"MY_SENTENCE"}", Crypto.generateSecretKey(), Crypto.generateIv())
vars.put("enc_data", encrypted);
Body Data in HTTP Request.
{ "data": "${enc_data}" }
In Results Tree
Request Body data was not url-encoding.
I want to send a data of url encoding, what should I do?
I don't know that.
I wrote Body Data in HTTP Request. So, I can't click the Parameters.
And I added Content encoding (UTF-8) it was not working too.
Either use __urlencode() function in the Body Data tab directly:
{ "data": "${__urlencode(${enc_data})}" }
JMeter Functions can be placed anywhere in the test plan and they're evaluated in the place where they're present so your ${enc_data} variable will be url-encoded in the runtime. See Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.
or call URLEncoder.encode() function in your Groovy script directly:
vars.put("enc_data", URLEncoder.encode(encrypted,"UTF-8"));

JMeter - Unable to click Parameter tab when added Body Data

Why I cannot click on Parameters tab in HTTP Request section after I insert JSON body data in Body Data tab? I tried to define correlation and of course this will require us to define the variable as well. Just wondering, after I'm done with correlation part, how can I insert the variable in Parameters if it is disabled?
You can't send Parameters and Body Data, you must choose only one option of sending request body
If you need to send extra parameters in additional to request body then use query parameters in Path field, for example
path?parameter1=value&parameter2=value2
If you want to variablize/correlate the JSON request body - you can put the relevant JMeter Functions/Variables directly into "Body Data" tab
as you can see all the functions/variables are getting replaced by their respective values.
Also most probably you're getting JSON as the response so it makes sense to consider switching to JSON Extractor or even better JSON JMESPath Extractor for the correlation.

Hapijs avoid json validation when Content-type: application/json is present

I'm trying to receive a json payload on a hapijs server, that json may not be valid, since is some custom format that i need to manually proxy the request to an elasticsearch cluster, cannot use the proxy option for hapijs because i need to do multiple requests to different clusters, for that i use nodejs http library.
Elasticsearch doesn't receive a valid json when doing bulk actions, it receives new lines instead of commas, to separate json objects:
{"index":[".kibana-devnull"],"ignore_unavailable":true}
{"size":500,"sort":[]}
Hapijs tries to validate the json payload when it gets application/json header in the request and it responds "Invalid request payload JSON format", as i cannot remove that header i need to look for another method to allow that invalid json in the route, even if the header is present.
I would look at the docs, in particular http://hapijs.com/api#route-configuration. If you set payload.output.parse to false you will receive the raw buffer inside handler which can then be parsed by yourself as opposed to by the framework.

JMeter - JSON Extractor post-processor

I've been trying to figure out how to configure a simple JSON Path extractor (provided on jmeter-plugins) and where to put it (inside an Http sample, outside...)
As you can see, ${expiredaccesstokenerror} is empty.
In order to fill this variable, I'm trying to extract a vallue from body response:
As you can see I'm trying to extract from json body content like:
{
"error_description":"Access token expired",
"suberror":"expired_accesstoken",
"error":"invalid_grant"
}
So, I've set JSON extractor for extracting $.suberror, however, it's always empty.
${expiredaccesstokenerror} in sampler is trying to get variable before request or response. In post processor you set the variable expiredaccesstokenerror but it's too late for displaying.

Posting JSON as a request parameter not sending it raw

I'm sending POST request on Jmeter with one of the parameters with json format. But JMeter is not sending it as a raw as you can see below. It's encoding the json and requesting with % and numbers... **msg** should be sending raw json.
I tried various options with encoding but none is working. How can I send json as a raw as a request parameter?
POST data:
trans_code=KycPartnerSender&version=1.0&pkg_id=1234123&timestamp=123123&**msg**=%7B%22sId%22%3A%7B%22weChatId%22%3A%22jnaS001%22%7D%2C%22sInfo%22%3A%7B%22firstName%22%3A%22jnaSender001%22%2C%22middleName%22%3A%22%22%2C%22lastName%22%3A%22QA%22%2C%22dob%22%3A%221958-01-31%22%2C%22email%22%3A%22001%40ZB.CA%22%2C%22taxId%22%3A%22467456789%22%2C%22mobilePhone%22%3A%224161231234%22%2C%22workPhone%22%3A%224161231234%22%2C%22citizenCountryCode%22%3A%22CA%22%2C%22residenceCountryCode%22%3A%22CA%22%7D%2C%22sAddress%22%3A%7B%22line1%22%3A%22123+Yonge+Street%22%2C%22line2%22%3A%22Suite+1902%22%2C%22city%22%3A%22Toronto%22%2C%22countryRegionCode%22%3A%22ON%22%2C%22postalCode%22%3A%22M2M2M2%22%2C%22countryCode%22%3A%22CA%22%7D%2C%22sFundingSource%22%3A%7B%22accountNumber%22%3A%22123456789%22%2C%22accountHolderName%22%3A%22JNA+SENDER%22%2C%22routingNumber%22%3A%2200402652%22%7D%2C%22rId%22%3A%7B%22weChatId%22%3A%22jnaR001%22%7D%2C%22rInfo%22%3A%7B%22firstName%22%3A%22jnaReceiver%22%2C%22middleName%22%3A%22X%22%2C%22lastName%22%3A%22QA%22%2C%22dob%22%3A%221970-10-31%22%2C%22email%22%3A%22002%40ZB.CA%22%2C%22taxId%22%3A%22789456123%22%2C%22mobilePhone%22%3A%224161231234%22%2C%22workPhone%22%3A%224161231234%22%2C%22citizenCountryCode%22%3A%22CA%22%2C%22residenceCountryCode%22%3A%22CA%22%2C%22employmentStatus%22%3A%22Full+Time%22%2C%22occupationCode%22%3A%22102%22%2C%22industryCode%22%3A%22101%22%7D%2C%22rAddress%22%3A%7B%22line1%22%3A%22123+Bloor%22%2C%22line2%22%3A%22Suite+1900%22%2C%22city%22%3A%22Toronto%22%2C%22countryRegionCode%22%3A%22ON%22%2C%22postalCode%22%3A%22M2M2M2%22%2C%22countryCode%22%3A%22CA%22%7D%2C%22rFundingSource%22%3A%7B%22accountNumber%22%3A%22987654321%22%2C%22accountHolderName%22%3A%22JNA+RECEIVER%22%2C%22routingNumber%22%3A%2200402652%22%7D%7D
Instead of using Parameters table, select the Raw Body tab and just put your json body.
Of course it only works with Post method (not Get) so it should be ok for you.

Resources