我试图将文件从 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/