HTTP POST mutli part “BAD REQUEST”

蓝咒 提交于 2020-01-05 06:51:07

问题


I'm trying to upload a file using POST

here's my request :

POST /upload.php HTTP/1.1
Host: localhost
Content-Type: multipart/form-data; boundary=---------------------------552335022525
Content-Length: 192
-----------------------------552335022525
Content-Disposition: form-data; name="userfile"; filename="12.txt"
Content-Type: text/plain


blabla
-----------------------------552335022525--

Using HTTP live headers firefox plugin everything works

but when putting it a char *buffer and send it with winsocksapi I get 400 Bad Request error


回答1:


You need a blank line between the headers and the payload.

Content-Length: 192

-----------------------------552335022525

This is part of the HTTP protocol. HTTP request headers end with the first empty line (CR-LF by itself.) What you are sending is resulting in the string

-----------------------------552335022525

being taken (along with the following two lines) as a request header which, of course, it isn't. The server can't make head or tail of that, so it responds with 400 Bad Request.

Also, sending the Content-length is not necessary with multipart/form-data, nor even a good idea, as the wrong value could create problems. The MIME multipart format is self describing.



来源:https://stackoverflow.com/questions/14056011/http-post-mutli-part-bad-request

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