读书人

C语言post引发的400 Bad Request异常

发布时间: 2012-09-14 11:53:44 作者: rapoo

C语言post引发的400 Bad Request错误
sprintf(request, "POST ....../poster.php?uid=%s http/1.1\r\n"
"Host: %s\r\n"
"User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1\r\n"
"Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Connection: keep-alive\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: %d\r\n\r\n%s",UID(), strHost, strlen(pData),pData);
自己封闭的头部,将request与要发送的数据拼接后发送出出去。

结果是,在自己搭建的phpstudy的环境下,服务器上的post.php顺利响应,回复http ok 200消息,数据确认发送到了服务器。

但在构买的空间主机上,IIS服务器,对此的回应是400 bad request消息。上面头部的消息各字段也有几次修改,poster.php脚本均没有响应。

哪位遇到过类似的问题么?怎么解决?


[解决办法]
sprintf(request, "POST ....../poster.php?uid=%s http/1.1\r\n"


sprintf(request, "POST /poster.php?uid=%s HTTP/1.1\r\n"

你的报文格式不规范,自己百度,不罗嗦
[解决办法]
浏览器访问,抓个包对比对比

读书人网 >C++

热点推荐