Jmeter: send image and other parameters together in post request - performance

I am testing an api. I need to upload image with api key. I can upload image separately but I can't post image and api key together.
{
"apikey" : "12345kjl",
"image" : ""
}

It depends on your server implementation, in some cases you need to post a Base64-encoded image, in this case you can use __FileToString() and __base64Encode() functions combination like:
{
"apikey" : "12345kjl",
"image" : "${__base64Encode(${__FileToString(/path/to/the/file,,)},)}"
}
Another option is building a multipart post request manually so it will look like:
--boundary
Content-Type: application/json; charset=UTF-8
JSON Metadata
--boundary
Content-Type: file MIME type
File content
--boundary--
See Testing REST API File Uploads in JMeter article for step-by-step instructions on implementing it.
In general you should capture "real" request using a sniffer tool like Fiddler or Wireshark and configure JMeter in order to send the same request (apart from dynamic parameters)

Since, I was able to upload image from postman. I used jmeter to record the script form postman and use exact recorded configuration in jmeter script.
I send "apikey" from Parameters section and image from "File Upload".
I didn't add header manager.
Actually content-type in header manager was causing the problem.

Related

Graphql with Jmeter

I am trying to use jmeter to Automate graphql API testing. I have done the manual testing with postman. However, since some one suggested i am trying to automate with jmeter. unfortunately i am new to API testing itself and having great difficulties.
As i understand Graphql method only deals with POST, but in my Jmeter it is throwing an error, but when i change it to GET, i get 200 ok response.
Also in the body data i am directly entered the graphQL query is this correct.
In the return response data i don get any information related to my query.
I have added header manager with
Content-type = "Application/json"
Accept-encoding
Authorization
Accept
Connection
My graphql query is
query{cmCases(filters: {caseId:"case-6"})
{
items {
id
}
}
}
In the response i am just receiving meta data.
Looking into HTTP Methods, Headers, and Body chapter of the GraphQL documentation GraphQL supports both GET and POST methods so you can choose whatever you want or whatever you need
Looking into HTTP Headers documentation chapter header values are case-sensitive so you need to change Application/json to application/json in the HTTP Header Manager
Given you can successfully execute request in Postman you should be able to record this request by JMeter's HTTP(S) Test Script Recorder, just configure Postman to use JMeter as the proxy
Starting with upcoming JMeter 5.3.1 or 5.4 you’ll be able to use the GraphQL Http Request.
Until it is released you can try a nightly build:
https://ci.apache.org/projects/jmeter/nightlies/
See:
https://github.com/apache/jmeter/pull/627

Post Request getting failed due to webkitformboundary in JMeter

We have a recorded script using Blaze Meter(HTTPS call) and run in JMeter, One POST request getting failed and shows "500 Internal Server error". In Post request, JSON passed in form of "form-Data" as parameter. When endpoint executed we observed Webkitformbounday in HTTP header, Please give some solution for
HTTPs Request
HTTP Header Manager
POST Request Body
enter image description here
It looks like the recording solution you're using isn't very suitable for building proper HTTP POST request, I would suggest the following amendments:
Untick Use multipart/form-data box in the HTTP Request sampler
Remove issueDetail parameter name and put it to the end of "path"
Change Content-Type header value to application/json
Authorization header value might need to be correlated if the token life span is short
More information: Testing SOAP/REST Web Services Using JMeter

Apache Nifi : How to pass post params and capture response from post API - traditional non rest, non json API

I'm trying to pull data from a post API that expects authentication and request parameters as part of the request body. I guess, what they do is access the data from the post variables.
What I have seen so far in documentation is how to send POST via JSON or headers. In my case, no headers just the post body parameters.
call to this api via curl --data option works just fine.
curl --data "username=xyz&password=xyz&function=xyz" http://example.com/api.php
How can I replicate above call in nifi?
I have tried multiple methods without success. Latest has been Generate flow file, update attributes (where i fill in the parameters), invoke http then putfile.
But I'm getting errors - the api is not abe to authenticate my request.
Thanks
If you need to send the following data in body, then put it into content of your flowfile.
username=xyz&password=xyz&function=xyz
The easiest way to put it into the Custom Text property of the GenerateFlowFile processor.
Usually for this kind of body you have to provide content type header:
content-type: application/x-www-form-urlencoded
If you don't need any additional headers then you don't have to define any additional attributes of the flow file.

How to POST data in in REST API using J meter

by HTTP request
enter image description herebase url is: http://124.124.21.165:8093/FieldApp/Service.svc/
Your configuration looks good, I would suggest just adding a HTTP Header Manager to send Content-Type header with the value of application/json
Also it would be good to add View Results Tree listener to inspect request and response details (don't forget to remove or disable it when it comes to running the load test assuming large amount of users)
Check out Testing SOAP/REST Web Services Using JMeter test plan for step-by-step instructions

RESTserver POST request format

I am developing an API using CodeIgniter and the RestServer for CI (see below). I am also using the Firefox RestClient plugin to test the API.
What I am wondering is how to do the test post (what format).
Tried {"desc":"value"} but it did not work. The API is not "seeing" the incoming post fields.
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
the post body doesn't need to have a specific format, but the most convenient is to encode the body in the same way web browsers encode form data, specifically Content-Type: application/x-www-form-urlencoded. In particular, the Host and Content-Length headers are not optional, and the Content-Type header is usually needed to tell the server how to interpret the body. A well formed POST request will look like:
POST /path/to/resource HTTP/1.0
Host: example.com:80
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
key=value&key2=value2
It's still up to the server to recognize the content-type header and parse the body that way.
Note that the data is after all the headers, not as part of the request path (in the first line).
Optionally, you can use Proxy Library which i wrote for CI. With that, you can simulate any of possible call to your API(its works for popular REST API too), with more simple syntax instead using cURL...
// An example call to your API end point using POST, will be simply
$this->load->library('proxy');
$this->proxy->http('POST', 'http://somesite.com/api/users', array('username' => 'foo', 'password' => 'bar'));
You can define whatsoever HTTP header too (like API Key or whatever else).

Resources