Just wanted a clarification of the form content types:
application/x-www-form-urlencoded
: This is where you can send params encoded with the url.
multipart/form-data
: ??
I need to send a JSON in the post (so it would have the type: text/x-json
, I guess). So the question is, is multipart/form-data
suitable for this purpose / is application/x-www-form-urlencoded
better?
Also, would it be possible to send some params encoded in the url, and some data in the json?
text/plain was typically used for JSON, but according to IANA, the official MIME type for JSON is application/json .
You can send only the following content types in a POST request to Media Server: application/x-www-form-urlencoded. multipart/form-data.
No, it's not mandatory. Per the HTTP 1.1 specification: Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body.
POST requests In Postman, change the method next to the URL to 'POST', and under the 'Body' tab choose the 'raw' radio button and then 'JSON (application/json)' from the drop down. You can now type in the JSON you want to send along with the POST request. If this is successful, you should see the new data in your 'db.
It looks like people answered the first part of your question (use application/json).
For the second part: It is perfectly legal to send query parameters in a HTTP POST Request.
Example:
POST /members?id=1234 HTTP/1.1 Host: www.example.com Content-Type: application/json {"email":"[email protected]"}
Query parameters are commonly used in a POST request to refer to an existing resource. The above example would update the email address of an existing member with the id of 1234.
I have wondered the same thing. Basically it appears that the html spec has different content types for html and form data. Json only has a single content type.
According to the spec, a POST of json data should have the content-type:
application/json
Relevant portion of the HTML spec
6.7 Content types (MIME types)
...
Examples of content types include "text/html", "image/png", "image/gif", "video/mpeg", "text/css", and "audio/basic".17.13.4 Form content types
...
application/x-www-form-urlencoded
This is the default content type. Forms submitted with this content type must be encoded as follows
Relevant portion of the JSON spec
- IANA Considerations
The MIME media type for JSON text is application/json.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With