熟悉HTTP协议的请进

wangjs720 2008-07-16 04:34:41
std::string str = "GET /search.php?city=北京 HTTP/1.1\r\n"
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*\r\n"
"Accept-Language: zh-cn\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)\r\n"
"Host: php.weather.sina.com.cn\r\n"
"Connection: Keep-Alive\r\n\r\n";

return ::send(_M_socket, str.c_str(), (int)str.length(), 0) == str.length();

发送后recv的数据为:

HTTP/1.0 503 Service Unavailable
Server: squid/2.6.STABLE13
Date: Wed, 16 Jul 2008 08:33:03 GMT
Content-Type: text/html
Cont

不知道为什么会返回错误503,动态网页不能用这种方式发送请求吗?
...全文
107 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
ok1234567 2008-07-16
  • 打赏
  • 举报
回复
如果可能,使用POST
如果可能,使用HTTP/1.0,而不是1.1 :)
hdqqq 2008-07-16
  • 打赏
  • 举报
回复
北京 需要转化一下. ie 里就有一个设置用UTF-8发送url
jwybobo2007 2008-07-16
  • 打赏
  • 举报
回复
这个问题不好说,但"北京"出问题是最有可能的,一般都需要把汉字编码一下
cppwin 2008-07-16
  • 打赏
  • 举报
回复
可能是 "北京" 的原因.

试试, 将北京用 16进制来表示 search.php?city=%B1%B1%BE%A9
yjgx007 2008-07-16
  • 打赏
  • 举报
回复
你的GET /search.php?city=北京 HTTP/1.1\r\n
中的 '北京" 应该encodeURI处理.
wangjs720 2008-07-16
  • 打赏
  • 举报
回复
同样的内容,用telnet就没问题

telnet php.weather.sina.com.cn 80

你可以试试,是没问题的
thirddata 2008-07-16
  • 打赏
  • 举报
回复
Service Unavailable 你的那个/search.php路径不对或不存在

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧