ACE 第一个练习:Web Client,解决了400 Bad Request问题,但不知为什么要这么做
2012-03-01 00:11
525 查看
#include "ace/INET_Addr.h" #include "ace/SOCK_Connector.h" #include "ace/SOCK_Stream.h" #include "ace/Log_Msg.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]){ const char *pathname=argc>1 ? argv[1]:"index.html"; const char *servername=argc>2 ? argv[2]:"ace.ece.uci.edu"; ACE_SOCK_Connector connector; ACE_SOCK_Stream peer; ACE_INET_Addr peer_addr; if(peer_addr.set(80,servername)==-1) return -1; else if(connector.connect(peer,peer_addr)==-1) return -1; char buf[BUFSIZ] = {0}; iovec iov[3]; iov[0].iov_base = "GET "; iov[0].iov_len = strlen("GET ") + 1; // 比实际大小多一个字节,不然会有400 Bad Request问题,不知道为什么 iov[1].iov_base = (char*)pathname; iov[1].iov_len = strlen(pathname); iov[2].iov_base = "HTTP/1.0\r\n\r\n"; iov[2].iov_len = 13; if(peer.sendv(iov, 3) == -1) return -1; for(ssize_t n; (n = peer.recv(buf, sizeof buf)) > 0; ) ACE::write_n(ACE_STDOUT ,buf ,n); system("pause"); return peer.close() == -1 ? 1 : 0; }
相关文章推荐
- ACE 第一个练习:Web Client,解决了400 Bad Request问题,但不知为什么要这么做
- ACE 第一个练习:Web Client,解决了400 Bad Request问题,但不知为什么要这么做
- 解决Form表单与后台参数不匹配的问题(Bad Request 400!!!)
- 解决Nginx 400 Bad Request问题的一些思路
- AndroidStudio问题Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request解决方法
- SpringMVC 400 Bad Request 问题解决
- VS2010 WCF 远程服务器返回了意外响应: (400) Bad Request等问题解决方案
- SpringMVC 400 Bad Request 问题
- SQL 2005 Report Server 请求因 HTTP 状态 400 失败: Bad Request 处理方法 的解决方法
- [练习][错误]SpringMVC错误:HTTP Status 400 – Bad Request
- Android开发:解决ErrorUnable to tunnel through proxy. Proxy returns HTTP1.1 400 Bad Request
- 微信小程序request出现400的问题解决办法
- nginx 解决400 bad request 的方法
- yii 提交表单 400 bad request问题
- nginx过一段时间出现400 Bad Request 错误的解决方法
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
- asmack register bad-request 400 问题 asmack-android-8-4.0.7注册问题
- spring mvc 前后端数据交互笔记(解决httprequest400,415问题)
- SpringMVC中出现" 400 Bad Request "错误的解决方法
- [已解决]XMPP访问7070/http-bind/出错:HTTP ERROR 400 Problem accessing /http-bind/ Reason: Bad Request Powere