iphone - 边界如何在多部分发布请求中工作?

标签 iphone http post http-post multipartform-data

我试图将文件从 iPhone 上传到服务器。我试图避免使用任何不是由 apple 制作的库,据我所知,我需要在构建请求时采取非常低的级别。有人能告诉我多部分/表单数据请求中的“边界”是什么以及如何正确使用它吗?

最佳答案

边界是一段任意文本,客户端使用它来分隔要发布的表单的字段。客户端将其使用的边界声明为 Content-type header 的一部分。

From the IETF Form-based File Upload in HTML RFC :

A boundary is selected that does not occur in any of the data. (This selection is sometimes done probabilisticly.) Each field of the form is sent, in the order in which it occurs in the form, as a part of the multipart stream. Each part identifies the INPUT name within the original HTML form. Each part should be labelled with an appropriate content-type if the media type is known (e.g., inferred from the file extension or operating system typing information) or as application/octet-stream.

...

6. Examples

Suppose the server supplies the following HTML:

<FORM ACTION="http://server.dom/cgi/handle"
       ENCTYPE="multipart/form-data"
       METHOD=POST>
 What is your name? <INPUT TYPE=TEXT NAME=submitter>
 What files are you sending? <INPUT TYPE=FILE NAME=pics>
 </FORM>

and the user types "Joe Blow" in the name field, and selects a text file "file1.txt" for the answer to 'What files are you sending?'

The client might send back the following data:

   Content-type: multipart/form-data, boundary=AaB03x

   --AaB03x
   content-disposition: form-data; name="field1"

   Joe Blow
   --AaB03x
   content-disposition: form-data; name="pics"; filename="file1.txt"
   Content-Type: text/plain

    ... contents of file1.txt ...
   --AaB03x--

If the user also indicated an image file "file2.gif" for the answer to 'What files are you sending?', the client might client might send back the following data:

   Content-type: multipart/form-data, boundary=AaB03x

   --AaB03x
   content-disposition: form-data; name="field1"

   Joe Blow
   --AaB03x
   content-disposition: form-data; name="pics"
   Content-type: multipart/mixed, boundary=BbC04y

   --BbC04y
   Content-disposition: attachment; filename="file1.txt"

在第一个例子中,边界是固定字符串AaB03x。在第二个示例中,边界首先是 AaB03x,然后切换到 BbC04y

关于iphone - 边界如何在多部分发布请求中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4027215/

相关文章:

iOS 在第 3 方应用程序中获取 Safari 保存的信用卡信息

iphone - 如何像 XCode 3 一样查看 XCode 4 中的对象层次结构?

java - 使用 Log4j2 公开 Http 客户端日志的问题

scala - 如何在 Spray/Scala/Java 中处理通过 HTML 表单上传的文件?

python - 用 bottle.py 读取 POST 正文

iphone - 带有 Web 服务的核心数据推荐模式?

ios - visual studio cordova 部署到 ios 设备失败和 visual studio 崩溃

http - golang : strategies to prevent connection reset by peer errors

PHP - 如果可用,如何重定向到 https?

c# - 请求参数不在 POST 请求中传输