Cannot sent pdf file via POST API using JSON Format - json

This is my json to send post request at one time.
[enter image description here]
It need me to send 3 parameter and 1 one of it is pdf file which must be String and encoded in Base64 string.
The file I have uploaded in postman>file location,
But after send the post request , I got this error.
enter image description here
I tried to sent Request using Postman in JSON format with the value is in String including the pdf file.
enter image description here

Such files you can send via form-data if your API supports it.
You can add multiple keys with type text or file. email and the name can by type text and the pdf file should be the type file. For the file uploads, you can send additional info and usually we send the file name as the key.
After adding the form data, postman request and curl would be like as follows.

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.

Issue while upload/send file with post request using Jmeter

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.

Why Post Data in Jmeter is going as --1Ls95bBrGMOsS5H7hQGp9_uJf_Z50M7-vQR-- when i am sending {"employee":"622083"}

I am using below url to send multiple request via json file
https://www.testingexcellence.com/jmeter-tutorial-how-to-send-a-json-file-as-request-in-body/
I put ${__FileToString(C:\PStech\${__eval(${JSON_FILE})}.txt,,)} in Body Data of Http request of Jmeter and using csv to send multiple json files which here I stored as 100.txt and 101.txt.
But I see Request is going as below
POST data:
--1Ls95bBrGMOsS5H7hQGp9_uJf_Z50M7-vQR--
Ideally it should send Request as {"employee":"622083"}
enter image description here
enter image description here
enter image description here
You need to untick Use multipart/form-data for HTTP POST box in the HTTP Request sampler.
Instead of this add HTTP Header Manager to send Content-Type header with the value of application/json
More information: REST API Testing - How to Do it Right

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.

Sending POST from HTML

I have an API at
http://example.com/createclass
In order to create a database entry I need the URL to be
http://example.com/createclass/:classid/:classname/:someotherid
How do I manipulate the URL string from my html page (This page takes input from the user)?
I do not want to send the body as a JSON. I know how to do that by serializing the form data into JSON and then sending it. I want to send the POST request to the following URL format:
http://example.com/createclass/200/blah/ksjdf32ebr21