Sending multipart/mixed content with Postman Chrome extension - google-chrome

I'm struggling with creating POST multipart/mixed request with Postman Chrome extension
Here is my curl request what works nice
curl -H "Content-Type: multipart/mixed"
-F "metadata=#simple_json.json; type=application/json "
-F "content=#1.jpg; type=image/jpg" -X POST http://my/api/item -i -v
interesting part of response
Content-Length: 41557
Expect: 100-continue
Content-Type: multipart/mixed; boundary=----------------------------8aaca457e117
additional stuff not fine transfer.c:1037: 0 0
HTTP 1.1 or later with persistent connection, pipelining supported
And when I use Postman
I getting such response
{"message":"Could not parse multipart servlet request;
nested exception is org.apache.commons.fileupload.FileUploadException:
the request was rejected because no multipart boundary was
found","type":"error","status":500,"requestId":"1861eloo6fpio"}
That's it - I wish to get rid of that error.
If some more information needed please ask :)

I was facing this problem too. Short answer: remove the Content-Type header from your Postman request.
The long story is that the Content-Type for a multipart request should be rather special -- it should look kind of like this:
multipart/form-data; boundary=----WebKitFormBoundaryzeZR8KqAYJyI2jPL
The problem is that the boundary is important and it needs to exactly match the boundary used to separate the files being uploaded. The solution is simple: do not specify a Content-Type! When you upload files, Postman will automatically append the above content type for you, except the boundary will be filled in with whatever Postman or Chrome is using to separate the multipart content.
You can verify this behavior by using Chrome developer tools (within Postman) to examine the Content-Type header being added, in addition to the Content-Disposition headers of the multipart data, which are also a pain to construct manually (and impossible within Postman).
Note: My answer is a solution for those who need a multipart/form-data answer. The OP was looking for a multipart/mixed solution. My answer will not suffice in this scenario. That being said, it seems a lot of people just want the multipart/form-data solution, so I will leave my answer here.

Left this comment on: https://github.com/postmanlabs/postman-app-support/issues/1104
Ninja update: Not sure if this will help anyone else but there is a workaround for a specific scenario where you have multiple file types / content types being uploaded in a single multipart POST request.
Set the Header Content-Type to multipart/mixed.
Select the form-data option in Body.
Convert all of your items into files. String content should become a text file, etc.
Add each file by selecting file, adding a key name.
This approach doesn't require actually manually specifying each Content-Type or Content-Disposition. The trick here was to serialize all relevant content into a persistent file type. You can ignore the "convert it into a file" step if it's text :) Hope that helps someone!

Related

PhpStorm/WebStorm REST client: easy way to send JSON?

In 2017 versions of PhpStorm / WebStorm there is a REST client we can use to send requests and analyze responses.
By default, when I send a POST and use the easy form in the UI to create request params, the parameters are formatted as x-www-form-urlencoded
instrument=JPY&id=6
I want to send data as JSON. So I thought if I add the content-type: application/json header, the IDE would format the request params accordingly, but it doesn't.
Currently the only way I see to send stuff in JSON format is to craft the JSON myself and put it in the Request Body as Text section of the IDE
Am I missing an easy way to send JSON?
You're not missing it, it's not there yet. Please vote: https://youtrack.jetbrains.com/issue/WEB-17342

How to make SoapUI json request work with german umlauts?

We use SoapUI for many interfaces in our team project. We came across a problem with german special signs, called umlauts. When sending a POST request with Json body and a german umlaut, the we get com.fasterxml.jackson.databind.JsonMappingException. It cannot be parsed with com.fasterxml.jackson.databind.ObjectMapper.
But when sending the same request using POSTMAN, then it works like a charm.
We use #Consumes({MediaType.APPLICATION_JSON + "; charset=utf-8"}) annotations and Content-Type: application/json; charset=utf-8 header. But still no effect. Has anyone ever came across such a problem or know how to solve it? We cannot change the testing tool.
In SoapUI there is an additional property for setting the encoding of your request.
It is available under the tab Request Properties.
Property: Encoding, Value: UTF-8.
Setting it as above solved our problem.

Jmeter is not recording the page where "Content-Type: application/octet-stream" is present

I was trying to record a webpage using Jmeter tool.
Functionality : The webpage collects data and send it to the server when "SUBMIT" is clicked.
During Recording : The webpage only refreshes itself without sending any data to the server.
Investigation : The webpage contains the following Request Header-
------WebKitFormBoundaryBuGANZEvO85y5f29
Content-Disposition: form-data; name="ctl00$CP1$fileExteneralRecords"; filename=""
Content-Type: application/octet-stream
Inference : It is observed that whenever we try to record a page which contains this "Content-Type: application/octet-stream", we are facing the same problem.
Can anybody help us in recording the webpage where this content type is appearing? Any kind of suggestion is most welcome.
It looks like you are trying to upload a file. JMeter can record this kind of events, however you need to put the file(s) under JMeter's "working directory" - usually /bin folder - so it could pick them up during recording and replay.
See JMeter Bug 48479 for detailed explanation and Performance testing: Upload and Download Scenarios with Apache JMeter guide for a set of recommendations on proper simulation of file uploads/downloads in your JMeter test.
I also observed same issue and resolved by
recording http sampler by some other means like blazemeter, fiddler, saving as HAR and converting to jmx.
Just select "use multipartform-data for POST" option of http sampler and remove "content-type" parameter from its header
referring link:- How to send a POST request a file with Content-Type: application/octet-stream in Node js

POST: sending a post request in a url itself

I have been given a url .. www.abc.com/details and asked to send my name and phone number on this url using POST. They have told me to set the content-type as application/json and the body as valid JSON with the following keys:
name: name of the user
phone number: phone number of the user
Now i have no clue how to send this request! Will it be something like:
http://www.abc.com/details?method=post&name=john&phonenumber=445566
or do i have to use java to send the same?
Please help
Based on what you provided, it is pretty simple for what you need to do and you even have a number of ways to go about doing it. You'll need something that'll let you post a body with your request. Almost any programming language can do this as well as command line tools like cURL.
Once you have your tool decided, you'll need to create your JSON body and submit it to the server.
An example using cURL would be (all in one line, minus the \ at the end of the first line):
curl -v -H "Content-Type: application/json" -X POST \
-d '{"name":"your name","phonenumber":"111-111"}' http://www.example.com/details
The above command will create a request that should look like the following:
POST /details HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 44
{"name":"your name","phonenumber":"111-111"}
You can post data to a url with JavaScript & Jquery something like that:
$.post("www.abc.com/details", {
json_string: JSON.stringify({name:"John", phone number:"+410000000"})
});
It is not possible to send POST parameters in the URL in a straightforward manner. POST request in itself means sending information in the body.
I found a fairly simple way to do this. Use Postman by Google, which allows you to specify the content-type (a header field) as application/json and then provide name-value pairs as parameters.
You can find clear directions at [2020-09-04: broken link - see comment] http://docs.brightcove.com/en/video-cloud/player-management/guides/postman.html
Just use your URL in the place of theirs.
You can use postman.
Where select Post as method.
and In Request Body send JSON Object.
In windows this command does not work for me..I have tried the following command and it works..using this command I created session in couchdb sync gate way for the specific user...
curl -v -H "Content-Type: application/json" -X POST -d "{ \"name\": \"abc\",\"password\": \"abc123\" }" http://localhost:4984/todo/_session
If you are sending a request through url from browser(like consuming webservice) without using html pages by default it will be GET because GET has/needs no body. if you want to make url as POST you need html/jsp pages and you have to mention in form tag as "method=post" beacause post will have body and data will be transferred in that body for security reasons. So you need a medium (like html page) to make a POST request. You cannot make an URL as POST manually unless you specify it as POST through some medium. For example in URL (http://example.com/details?name=john&phonenumber=445566)you have attached data(name, phone number) so server will identify it as a GET data because server is receiving data is through URL but not inside a request body
In Java you can use GET which shows requested data on URL.But POST method cannot , because POST has body but GET donot have body.

Do HTTP POST methods send data as a QueryString?

I'd like to know if the POST method on HTTP sends data as a QueryString, or if it use a special structure to pass the data to the server.
In fact, when I analyze the communication with POST method from client to server (with Fiddler for example), I don't see any QueryString, but a Form Body context with the name/value pairs.
The best way to visualize this is to use a packet analyzer like Wireshark and follow the TCP stream. HTTP simply uses TCP to send a stream of data starting with a few lines of HTTP headers. Often this data is easy to read because it consists of HTML, CSS, or XML, but it can be any type of data that gets transfered over the internet (Executables, Images, Video, etc).
For a GET request, your computer requests a specific URL and the web server usually responds with a 200 status code and the the content of the webpage is sent directly after the HTTP response headers. This content is the same content you would see if you viewed the source of the webpage in your browser. The query string you mentioned is just part of the URL and gets included in the HTTP GET request header that your computer sends to the web server. Below is an example of an HTTP GET request to http://accel91.citrix.com:8000/OA_HTML/OALogout.jsp?menu=Y, followed by a 302 redirect response from the server. Some of the HTTP Headers are wrapped due to the size of the viewing window (these really only take one line each), and the 302 redirect includes a simple HTML webpage with a link to the redirected webpage (Most browsers will automatically redirect any 302 response to the URL listed in the Location header instead of displaying the HTML response):
For a POST request, you may still have a query string, but this is uncommon and does not have anything to do with the data that you are POSTing. Instead, the data is included directly after the HTTP headers that your browser sends to the server, similar to the 200 response that the web server uses to respond to a GET request. In the case of POSTing a simple web form this data is encoded using the same URL encoding that a query string uses, but if you are using a SOAP web service it could also be encoded using a multi-part MIME format and XML data.
For example here is what an HTTP POST to an XML based SOAP web service located at http://192.168.24.23:8090/msh looks like in Wireshark Follow TCP Stream:
Post uses the message body to send the information back to the server, as opposed to Get, which uses the query string (everything after the question mark). It is possible to send both a Get query string and a Post message body in the same request, but that can get a bit confusing so is best avoided.
Generally, best practice dictates that you use Get when you want to retrieve data, and Post when you want to alter it. (These rules aren't set in stone, the specs don't forbid altering data with Get, but it's generally avoided on the grounds that you don't want people making changes just by clicking a link or typing a URL)
Conversely, you can use Post to retrieve data without changing it, but using Get means you can bookmark the page, or share the URL with other people, things you couldn't do if you'd used Post.
http://en.wikipedia.org/wiki/GET_%28HTTP%29
http://en.wikipedia.org/wiki/POST_%28HTTP%29
As for the actual format of the data sent in the message body, that's entirely up to the sender and is specified with the Content-Type header. If not specified, the default content-type for HTML forms is application/x-www-form-urlencoded, which means the server will expect the post body to be a string encoded in a similar manner to a GET query string. However this can't be depended on in all cases. RFC2616 says the following on the Content-Type header:
Any HTTP/1.1 message containing an entity-body SHOULD include a
Content-Type header field defining the media type of that body. If
and only if the media type is not given by a Content-Type field, the
recipient MAY attempt to guess the media type via inspection of its
content and/or the name extension(s) of the URI used to identify the
resource. If the media type remains unknown, the recipient SHOULD
treat it as type "application/octet-stream".
A POST request can include a query string, however normally it doesn't - a standard HTML form with a POST action will not normally include a query string for example.
GET will send the data as a querystring, but POST will not. Rather it will send it in the body of the request.
If your post try to reach the following URL
mypage.php?id=1
you will have the POST data but also GET data.