上传内容时,HTTP-Request中的内容类型值是什么? [英] Whats Content-Type value within a HTTP-Request when uploading content?

查看:183
本文介绍了上传内容时,HTTP-Request中的内容类型值是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从http-trafic中提取上传内容。怎么可能呢?首先,请求方法将是POST。其次,将有一个Content-Type标头字段。我不想提取公式数据,而是上传像邮件附件。

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.

推荐答案

内容类型规范 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.

下面是一个示例,它看起来像1个普通字段和1个文件字段(用HTML表示,当使用<$时c $ c>< input name =textfield>< input type =filename =filefield> ):

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

关于解析和提取这些数据,几乎每种编程语言为此提供内置/第三方API。由于您没有说明您正在使用哪一个,因此无法给出有针对性的答案。在例如Java的情况下,可能是第三方库Apache Commons FileUpload,或者当您使用Servlet 3.0时,API提供的 request.getPart()方法。

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.

这篇关于上传内容时,HTTP-Request中的内容类型值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆