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

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

问题描述

我需要从 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 术语中,当使用 <input name="textfield"><input type="file" name="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--

至于解析和提取这些数据,几乎每种编程语言都为此提供了内置/第 3 方 API.由于您没有说明您使用的是哪一种,因此无法给出有针对性的答案.例如,在 Java 的情况下,这将是第 3 方库 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 请求中的 Content-Type 值是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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