Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Content-Type mandatory in HTTP post request?

Tags:

http

post

Is the field:

Content-Type

mandatory when I perform an HTTP request?

like image 777
user601836 Avatar asked Apr 07 '13 09:04

user601836


People also ask

What should be the Content-Type for POST request?

You can send only the following content types in a POST request to Media Server: application/x-www-form-urlencoded. multipart/form-data.

What happens if you don't set Content-Type?

1.5 explains that if Content-Type is not set, the server may assume the data is application/octet-stream or interpret the request any way it wants. But: Clients that do so risk drawing incorrect conclusions, which might expose additional security risks (e.g., "privilege escalation").

Is Content-Type optional?

A Content-Type header is optional. The MIME specification defines a part without a Content-Type header as text/plain; charset=us-ascii. RFC 2045 defines the Content-Type header in section 5 (p. 10).

What is the use of Content-Type in HTTP request?

The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending). In responses, a Content-Type header provides the client with the actual content type of the returned content.


Video Answer


1 Answers

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. 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".

That said, it's obviously going to be hard for the server to accurately interpret the data you're sending if you omit the Content-Type header, so it's not recommended to do so.

like image 183
bdash Avatar answered Sep 27 '22 20:09

bdash