Help, don't know what's wrong with my HTTP multipart POST

China☆狼群 提交于 2019-12-02 12:24:32

问题


POST /upload HTTP/1.1
Host: assets.drop.io
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.10) Gecko/2
009042316 Firefox/3.0.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Content-Length: 5728
Content-Type: multipart/form-data; boundary=--------MalolHCBdarysNYMHZbIvjbD


--------MalolHCBdarysNYMHZbIvjbD
Content-Disposition: form-data; name="api_key"

0b8a12109c3a1bfc4ba94aec926e1f9cfd8bb6f0
--------MalolHCBdarysNYMHZbIvjbD
Content-Disposition: form-data; name="drop_name"

4pgvoxc
--------MalolHCBdarysNYMHZbIvjbD
Content-Disposition: form-data; name="version"

2.0
--------MalolHCBdarysNYMHZbIvjbD
Content-Disposition: form-data; name="rachel"; filename="rachel"
Content-Type: application/octet-stream

BMv¶
--------MalolHCBdarysNYMHZbIvjbD--

The response I get is: Bad Request. And in the HTML of the response there is this:

:MultiPartParseError: bad content body:
'
----------MalolHCBdarysNYMHZbIvjbD' should == '----------MalolHCBdarysNYMHZbIvjbD
'></td></tr>

回答1:


The answer is in your question. The response says that the divider should be '----------MalolHCBdarysNYMHZbIvjbD ' instead of ' ----------MalolHCBdarysNYMHZbIvjbD'

Look at the leading and trailing spaces.




回答2:


The schematic syntax of a multipart/form-data message is as follows:

Content-Type: multipart/form-data; boundary=boundary

--boundary
Content-Disposition: form-data; name="field 1"

data 1
--boundary
Content-Disposition: form-data; name="field 2"

data 2
⋮
--boundary
Content-Disposition: form-data; name="field N"

data N
--boundary--

So the inner part boundaries are --boundary (-- followed by the boundary value) and the last is --boundary-- (-- followed by the boundary value followed by --).

In your case you are just missing the leading --.



来源:https://stackoverflow.com/questions/1992912/help-dont-know-whats-wrong-with-my-http-multipart-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!