首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

虚拟机ubutun 上HTTP GET 上载网页 返回失败

2013-02-24 
虚拟机ubutun 下HTTP GET 下载网页 返回失败char* HttpCreatePack(const char *url, const char*host){cha

虚拟机ubutun 下HTTP GET 下载网页 返回失败
char* HttpCreatePack(const char *url, const char*host)
{
char* buf = (char*)malloc(1024*4);
strcat(buf, "GET /");
strcat(buf, " HTTP1.1\r\n");
strcat(buf, "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap,application/x-ms-application, application/vnd.ms-xpsdocument, */*\r\n");
strcat(buf,"Accept-Language: zh-cn\r\n");
strcat(buf, "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)\r\n");
strcat(buf,"Host:");
strcat(buf,url);
strcat(buf,"\r\n");
strcat(buf,"Connection:Keep-Alive \r\n");
strcat(buf,"\r\n");
printf("%s\n",buf);
return buf;

}

这是我的请求包答应出来如下:
GET / HTTP1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/xaml+xml, application/x-ms-xbap,application/x-ms-application, application/vnd.ms-xpsdocument, */*
Accept-Language: zh-cn
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host:www.baidu.com
Connection:Keep-Alive

结果socket没有返回
把URL改成www.163.com 结果socket返回:
HTTP/1.0 502 Bad Gateway
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>

以上端口设置都是80  是不是请求包设置错误了 至少代理User-Agent:选项应该是linux的 但我认为这个没有影响?求指点

[解决办法]
GET / HTTP/1.1

热点排行