Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats Content-Type value within a HTTP-Request when uploading content?

I need to extract uploads from http-trafic. How could do that? First of all, the request-method will be POST. Secondly, there will be a Content-Type header-field. I do not want to extract formular-data, but uploads like mail-attachements.

like image 262
user1826831 Avatar asked Feb 19 '13 16:02

user1826831


People also ask

What is 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.

What is the content type of a GET request?

HTTP GET and DELETE requests specify all of their input parameters on the URI using standard encoding. There is no body in such requests. The content type of the requests for these is always x-www-form-urlencoded, since that is all that is allowed for GET and DELETE requests by the HTTP protocol.

Is content type required in request?

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.

What is content type?

Definition of a Content Type. In technical terms, a Content Type is a reusable collection of metadata for a category of content, with its corresponding taxonomies that allows you to manage information in a centralized, reusable way.


1 Answers

The content type is per specification multipart/form-data.

This is a special content type which can be visualized as multiple sub-requests in one big request. Each of those sub-requests (one form-data element) has their own set of headers. The content type of the actual data is in there.

Here's an example how it look like with 1 normal field and 1 file field (in HTML terms, when using <input name="textfield"><input type="file" name="filefield">):

Content-Type: multipart/form-data;boundary=SOME_BOUNDARY  --SOME_BOUNDARY content-disposition: form-data;name="textfield" content-type: text/plain;charset=UTF-8  value of textfield here --SOME_BOUNDARY content-disposition: form-data;name="filefield";filename="some.ext" content-type: application/octet-stream  binary file content here  --SOME_BOUNDARY-- 

As to parsing and extracting this data, practically every programming language has builtin/3rd party APIs for this. As you didn't tell anything about which one you're using, it's impossible to give a targeted answer. In case of for example Java, that would be either the 3rd party library Apache Commons FileUpload or when you're using Servlet 3.0, the API-provided request.getPart() method.

like image 89
BalusC Avatar answered Oct 01 '22 13:10

BalusC