Issue while upload/send file with post request using Jmeter - json

I have one post request where I am uploading image as per below using postman :
I am trying to perform same request using Jmeter. I did following setting in Jmeter :
But somehow it is not working. I tried with multipart/form-data for POST option also but no luck.
our API developer has set validation that if api get any other file then image then they send response : invalid file type. I am getting this response all time when do POST request with image from Jmeter. It works fine with postman.
In Debugger post processor it shows like this : HTTPsampler.Files=path:'C:\apache-jmeter-4.0\bin\samplex.png'|param:'fileName'|mimetype:'image/png'

Finally I was able to resolve issue by removing Parameter name and MIME Type from tab File Upload. I did provide only file path and it works. Also I unchecked Use multipart/form-data for POST

You see button Browse.. in picture 2 you post. Do for same with Postman, choose file and send the request.

Make sure you have a valid file at the specified path.
Check your postman whether it is sending any other things in the header like Content-Type.
Check out File Uploads using JMeter guide for more information on simulating file uploads with JMeter

As I wrote in comment, If you want to send binary file as is (not as parameter value), remove the Parameter Name column value (file)
See JMeter's HTTP Request reference for more details:
File Path: Name of the file to send. If left blank, JMeter does not send a file, if filled in, JMeter automatically sends the request as a multipart form request.
If it is a POST or PUT or PATCH request and there is a single file whose 'Parameter name' attribute (below) is omitted, then the file is sent as the entire body of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests, and also for PUT requests.

Related

IIS not returning content if .html file contains no markup

Google sent me file to put on my website in order for me to validate that I have control of the domain: google123456789.html. The file contains no markup:
google-site-verification: google123456789.html
When I try to access the URL, I just get a 200 response but no payload. Why?
Troubleshooting
If I add <html>...</html> tags to the payload is downloaded...but the Google verification fails, probably because the file content isn't exactly what it expects.
If I change the file to be .txt, the payload is downloaded...but the Google verification fails because the URL of the file isn't what it's expecting.

Pentaho HTTP Post multipart/form-data

I am trying to use HTTP Post to post the data by passing following Header and Body part,
Body:
One image URL having file path. Type as 'File'
Metadata in JSON format. Type as 'Text'
Headers:
Content-type = multipart/form-data
Authorization = Bearer 5412
Here is the screenshot of complete request,
This is how I have setup the HTTP Post task in Pentaho,
I found related post here using REST Client but this also didn't help: Pentaho HTTP Post using JSON
Really appreciate your help.
I think the problem is that "Post a file" doesn't mean include a file in the request, but rather to get the entire request from that file.
I don't know the specifics of how the data should look in the Post request, but the rough approach should be:
Pass the filename field to a Calculator step with the operation "Load file content to binary" to get a binary type field (ex: myimage)
Base64 (or other) encode the data with a Javascript step like this:
var encString = new Packages.java.lang.String( Packages.org.apache.commons.codec.binary.Base64.encodeBase64( myimage ) );
Wrap it in some content-type string indicating the encoding
Include the field in your request.
There is a patch on https://jira.pentaho.com/browse/PDI-14743 to enable proper binary transfer instead of String when using Rest Client.

Track navigation with jmeter

I try to make a stress test with jmeter: i set up jmeter proxy to record navigation and everythings is ok.
I have some problem with a page wich has a json request called by javascript: using the jmeter proxy this request doesn't works.
With firebug I can see that the response of json request is
{"error":{"msg":"couldn't parse request arguments","code":590}}
It seems that jmeter proxy modify the parameter request.
With this error, I cannot use this page: any suggest?
Thanks
Aldo
JMeter isn't able to execute JavaScript, you'll need to construct the request manually. Perhaps you'll need to get some parameter(s) from page source via Regular Expression Extractor. Once you figure out correct request make sure that you'll add Content-Type header application/json via HTTP Header Manager

How to transfer large xml file and zip file via rest api?

I have an application which uploads a large file in the XML format and sometimes a zip file. Now I want to have that file transferred to other application via REST API. I am thinking to pass the binary data in to json response.
I have the following questions for my approach.
Is sending binary in json the best approach/practice to do it?
Will this be PUT scenario as receiver application doesn't know about new uploaded file?
If that makes it easier for the second service to consume it, I see no problem with it. You can send it on any format you want, as long as it's accepted and you're setting the Content-Type and Accept headers properly.
You use a PUT only when you're sending a complete replacement of the resource at the target URI. If you know the final URI for that and if a GET to the same URI right after the PUT will retrieve as response the same body you just submitted, it makes sense to use PUT, otherwise, use a POST.

how to send a file as a request as a raw http request body

I have working http request call with JSON body. WHat I want to do is to use the same content as an external file. For this I have used "send files with the request" function, without using multi-part because our server doesn't support that. I tried with or without parameter name or MIME type and the result is the same 400. The same call is working if instead I use the JSON in the body.
File location is good, i double checked that. THe actual content of the file is not displayed in the request.
Any ideas?
As per documentation:
http://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request
Name of the file to send. If left blank, JMeter does not send a file, if filled in, JMeter automatically sends the request as a multipart form request.
If it is a POST or PUT or PATCH request and there is a single file whose 'Parameter name' attribute (below) is omitted, then the file is sent as the entire body of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests after version 2.2, and also for PUT requests after version 2.3. See below for some further information on parameter handling.
You can use the Jmeter function __fileToString for that:
https://jmeter.apache.org/usermanual/functions.html#__FileToString