首页 > boost asio http post 返回404 错误

boost asio http post 返回404 错误

尝试用boost asio 获取服务器数据,但是服务器一直返回404错误,用wireshark抓包看了下,和成功的获取发送的报文也一样 ,不知道什么原因。贴些数据上来:
POST /cus_order/order_interface/interface_transite_search.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf8
User-Agent: said
Cache-Control: no-cache
Pragma: no-cache
Host: order.yundasys.com:10235
Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2
Connection: keep-alive
Content-Length: 174

parnerid=3100731120&version=1.0&validation=111f3dd5c60e8a3d2dba3178f95fc473&xmldata=PG1haWxub3M%2BPG1haWxubz4zMTAwNTYzODcxMzY3PC9tYWlsbm8%2BPC9tYWlsbm9zPg%3D%3D&request=dataHTTP/1.1 404 Not Found
Server: nginx
Date: Thu, 17 Sep 2015 03:06:19 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive

自己用java实现了一个相似的功能,使用了java自带HttpURLConnection,服务器可以正常返回数据:
POST /cus_order/order_interface/interface_transite_search.php HTTP/1.1
Content-Type: application/x-www-form-urlencoded;charset=utf8
User-Agent: said
Cache-Control: no-cache
Pragma: no-cache
Host: order.yundasys.com:10235
Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2
Connection: keep-alive
Content-Length: 174

partnerid=3100731120&version=1.0&validation=111f3dd5c60e8a3d2dba3178f95fc473&xmldata=PG1haWxub3M%2BPG1haWxubz4zMTAwNTYzODcxMzY3PC9tYWlsbm8%2BPC9tYWlsbm9zPg%3D%3D&request=dataHTTP/1.1 200 OK
Server: nginx
Date: Thu, 17 Sep 2015 03:08:14 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 2727
Connection: keep-alive
X-Powered-By: PHP/5.3.3

对比下 request 没什么差别 ,
boost asio 简化后的实现:
std::string req = "POST /cus_order/order_interface/interface_transite_search.php HTTP/1.1\r\n"
"Content-Type: application/x-www-form-urlencoded;charset=utf8\r\n"
"User-Agent: said\r\n"
"Cache-Control: no-cache\r\n"
"Pragma: no-cache\r\n"
"Host: order.yundasys.com:10235\r\n"
"Accept: text/html, image/gif, image/jpeg, ; q=.2, /*; q=.2\r\n"
"Connection: keep-alive\r\n"
"Content-Length: 174\r\n\r\n"
"partnerid=3100731120&version=1.0&validation=111f3dd5c60e8a3d2dba3178f95fc473&xmldata=PG1haWxub3M%2BPG1haWxubz4zMTAwNTYzODcxMzY3PC9tYWlsbm8%2BPC9tYWlsbm9zPg%3D%3D&request=data";

boost::asio::write(socket, boost::asio::buffer(req));
while(boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error));
报文有一个不一样的地方就是,http post 之后 成功的返回数据的 中间有几条跟服务器确认的报文,但是boost 实现只收到服务器发的一个ack报文, 但是这就有另外一个问题, tcp 是面向连接的,post之前已经发起三次握手 建立连接了 后面发送请求应该是不需要协商什么了吧
不知大伙有没碰到这个问题。
【热门文章】
【热门文章】