How to add form-data in jmeter - testing

At POST API,
the developer has passed info with form-data
enter image description here
Need to test API in jmeter. But did not find an option for form-data.
So I tried to add with "parameter" and "Body Data", and now I am getting 400 at Response.
enter image description here
enter image description here

form-data assumes submitting a HTML Form, all the inputs need to be provided via "Name" and "Value" parameters:
If this is a multipart/form-data request - you need to tick the appropriate box
In case you need to send any files - specify them in the Files Upload tab:
If your request works fine in Postman the easiest way of replicating it in JMeter would be just recording it using JMeter's HTTP(S) Test Script Recorder
Start the HTTP(S) Test Script Recorder
Import JMeter's certificate into Postman, this way JMeter will be able to intercept and record HTTPS requests
Configure Postman to use JMeter as the proxy so the request to API would go through JMeter
Run your request in Postman
JMeter will generate HTTP Request Sampler and HTTP Header Manager
Correlate dynamic parameters if needed and replace recorded hard coded values with the relevant JMeter Variables
If the request assumes any files upload - make sure that the file(s) are placed in "bin" folder of your JMeter installation.
You should be able to run the request successfully now

Related

JMeter File Upload - Raw contents

I have a very peculiar scenario where the raw data of the file has to be sent. I have tried following options and still wasn't successful.
Http Request with form-data disabled but still its sending as multi-part which is not acceptable by the system
Sending the file contents in request body by following methods . They were successful however the file uploaded was encoded in some format so the MD5 hash of the original file and uploaded file doesn't match. Hence the uploaded file looked different from original
FileToString Method
Reading the file using HTTP request . Capturing the response and passing to the body of File upload request
Using Https Raw data . Since its https request, it cannot be used.
All possible encoding formats available but nothing worked as the application just expects the raw data without any encoding.
You're supposed to provide an example successful request and the file you're uploading, it can be captured using a sniffer tool like Wireshark or Fiddler, only this way we'll be able to come up with the relevant JMeter configuration required to replicate the request.
In the mean time I can only suggest trying recording the request using JMeter's HTTP(S) Test Script Recorder
Start JMeter's HTTP(S) Test Script Recorder
Import JMeter's certificate into your browser (or system certificates storage if the upload is being performed by other application), see HTTPS recording and certificates chapter of JMeter's documentation on HTTP(S) Test Script Recorder
Copy the file you're going to upload to "bin" folder of your JMeter installation (or JMeter's current working directory if you're launching it from a desktop shortcut or whatever), see Recording File Uploads with JMeter for more details
Perform the upload in the browser (or other application)
JMeter should intercept the request and generate proper HTTP Request sampler and HTTP Header Manager

Not able to upload image using upload file in Jmeter- Getting error in response

I am facing the issue when i try to upload file into the application after login into application, Manually it is working fine but when i tried to upload file using jmeter I am getting error can you please help me on this.
Screenshot of Jmeter HTTP
I have used the common approach to upload files but still I am getting message no document present as error.
Http request screenshot
and after running my script i am getting this request and response request Response
However on successful submission it should show status as true and message as successfully uploaded. Screenshot of browser developer tools
browser's request screenshot attached
Please help
We cannot help without seeing:
Successful request details from your browser developer tools
Full details of the request and response from JMeter's View Results Tree listener
The details of the file input and the relevant log of your application.
Given you're able to upload the image using the browser you could try recording your request using JMeter's HTTP(S) Test Script Recorder, just make sure to copy your PSM.png file to JMeter's "bin" folder, this way JMeter will be able to properly generate relevant HTTP Request sampler. See Recording File Uploads with JMeter article for more details.
I still can't see your browser's request screenshot. It would have helped to understand what browser client is sending.
Anyway, I see from your Jmeter request screenshot that you aren't using cookie manager in your script. Can you please add 'HTTP Cookie Manager' in your script and give it a try?

Jmeter: Binary File Upload Fails with 500 Internal Server Error

I have tried to upload a binary file, which works fine using POSTMAN as below:
Request Headers:
Request Parameter:
Request Body:
Here it works just fine.
I have tried the same Request Header and Body in Jmeter, but getting 500 internal server Error.
Please take a look into the below Jmeter configurations:
HTTP Request Parameter:
HTTP Request File Upload:
I am a new bee to JMeter. Can someone help me and let me know what is wrong in the configuration I have done?
Maybe some mismatch in terms of HTTP Headers, if you can successfully execute the request using Postman you should be able to record the same using JMeter's HTTP(S) Test Script Recorder
Start JMeter's HTTP(S) Test Script Recorder
Configure Postman to use JMeter as the proxy
Copy the file you will be uploading to the "bin" folder of your JMeter installation
Run your request in Postman
JMeter will save the relevant HTTP Request sampler along with the HTTP Header Manager under the Recording Controller

File Upload in Jmeter for POST method, when we have binary based form data

I am trying to perform a file upload operation using jmeter for an API POST method. In Jmeter it requests results in 403 but in webpage it is 200.
Referred as many online resources and given multiple attempts i am not able to crack the solution.
How to handle the below form data in jmeter 4.0, As you could notice, there are 2 things, files and filedetails. How to handle this ?
I have also included the header value. Please look into it.
Below is the form data of POST METHOD:
------WebKitFormBoundarylyJiQdD1alYKbAKW
Content-Disposition: form-data; name="files"; filename="Sample_Report.pdf"
Content-Type: application/pdf
------WebKitFormBoundarylyJiQdD1alYKbAKW
Content-Disposition: form-data; name="filedetails"
{"serviceRequestId":"RandomNumber","filedetails":[{"fileName":"Sample_Report.pdf","fileUniqueName":"Randomnumber-a575d680-ceb0-11e9-a25d-2590f89b0ed0.pdf","fileType":"application/pdf","fileSize":1117730,"status":"New"}]}
------WebKitFormBoundarylyJiQdD1alYKbAKW--
Request Headers:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarylyJiQdD1alYKbAKW
I should be able to upload a single / multiple file through the JMeter.
To upload a file using JMeter, try following approach:
Use HTTP Request Sampler and add all the necessary details like Server, Port, Path, Method etc.
In File Upload section of HTTP Sampler include following
File Path = Sample_Report.pdf
Parameter Name = files
MIME Type = multipart/form-data [if this does not work use application/pdf]
In Parameters section of HTTP Sampler include following
Name = filedetails
Value = {"serviceRequestId":"RandomNumber","filedetails":[{"fileName":"Sample_Report.pdf","fileUniqueName":"Randomnumber-a575d680-ceb0-11e9-a25d-2590f89b0ed0.pdf","fileType":"application/pdf","fileSize":1117730,"status":"New"}]}
Make sure to check Use multipart/form-data
Add header whichever is required in Header Manager [initially dont include this, if it does not work with above settings, then only include Header Manager]
The easiest way of configuring JMeter to simulate file upload is just recording it using HTTP(S) Test Script Recorder
Configure JMeter for Recording. The easiest way is using JMeter Templates feature
From JMeter's main menu choose "File -> Templates - Recording" and click "Create"
Expand HTTP(S) Test Script Recorder and click "Start"
Copy the file(s) you will be uploading to "bin" folder of your JMeter installation
Perform the upload in the browser
JMeter will generate the relevant HTTP Request sampler under the Recording Controller
For more complex scenarios you might require building your request manually, refer Testing REST API File Uploads in JMeter article for more details if needed.

Jmeter: Cannot upload file with put method in jmeter

I want to upload an image with put method in JMeter. Based on chrome-network, I set the same header and body data in JMeter.
header manager:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryMByG8MgRZu8H9cSQ
Body data
------WebKitFormBoundaryMByG8MgRZu8H9cSQ Content-Disposition: form-data; name="avatar"; filename="1.jpg" Content-Type: image/jpeg
------WebKitFormBoundaryMByG8MgRZu8H9cSQ--
But NoHttpResonseException appears in jmeter.
Could anyone do me a favour? Thanks.
The error you're getting doesn't seem to be connected with the file upload, it tells that JMeter is not able to connect the server so I would suggest testing baseline connectivity first of all.
Copying request body form the other tool won't help in case of file upload as these multipart requests are different beasts. Particularly in your case the relevant configuration would be:
Switch to the "File Upload" tab of the HTTP Request sampler
Set "method" to Post
Check use multipart/form-data box
Add the following parameter:
Filename: 1.jpg if the file is present in JMeter's "bin" folder, otherwise - full path to the file
Parameter Name: the name of the file input, in your case it is avatar
MIME type of the file, being uploaded, in your case it is application/jpeg
See Performance Testing: Upload and Download Scenarios with Apache JMeter article for comprehensive explanation on how to upload and download files in your JMeter web tests.
Alternative option of building the relevant request is just recording it using JMeter's HTTP(S) Test Script Recorder, in this case make sure 1.jpg file is present in JMeter's "bin" folder during test recording and execution.
for this part, I suggest you to try doing your action from postman. And if it is successful you just need to record action performed by postman via jmeter(Http(s) test script recorder). And then configure your jmeter accordingly later.
I had a similar issue and I followed above approach.
Thanks