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

前端 未结 3 859
日久生厌
日久生厌 2020-11-28 12:09

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 w

3条回答
  •  春和景丽
    2020-11-28 12:18

    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 ):

    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.

提交回复
热议问题