HTTP POST辑阵部分"坏请求" [英] HTTP POST mutli part "BAD REQUEST"

查看:146
本文介绍了HTTP POST辑阵部分"坏请求"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传使用POST文件

I'm trying to upload a file using POST

这里是我的要求:

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--

使用HTTP实时头Firefox的插件一切正常。

Using HTTP live headers firefox plugin everything works

但只是当一个char *缓冲区和winsocksapi发送我得到400错误请求错误

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

推荐答案

您需要的报头和有效载荷之间的空行。

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

Content-Length: 192

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

这是HTTP协议的一部分。 HTTP请求头(本身CR-LF)与第一空行到底是什么,你要发送的生成字符串

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

被取作请求首部,当然,这不是(与下面的两行沿)。服务器不能使头部或尾巴,所以它与400错误的请求进行响应。

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.

此外,发送内容长度是没有必要用的multipart / form-data的,甚至也不是一个好主意,因为错误的值可能会产生问题。 MIME多格式是自描述。

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.

这篇关于HTTP POST辑阵部分"坏请求"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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