当前位置: 技术问答>linux和unix
虚拟机ubutun 下HTTP GET 下载网页 返回失败
来源: 互联网 发布时间:2017-04-01
本文导语: char* HttpCreatePack(const char *url, const char*host) { char* buf = (char*)malloc(1024*4); strcat(buf, "GET /"); strcat(buf, " HTTP1.1rn"); strcat(buf, "Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-e...
char* HttpCreatePack(const char *url, const char*host)
{
char* buf = (char*)malloc(1024*4);
strcat(buf, "GET /");
strcat(buf, " HTTP1.1rn");
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, */*rn");
strcat(buf,"Accept-Language: zh-cnrn");
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)rn");
strcat(buf,"Host:");
strcat(buf,url);
strcat(buf,"rn");
strcat(buf,"Connection:Keep-Alive rn");
strcat(buf,"rn");
printf("%sn",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
502 Bad Gateway
The server returned an invalid or incomplete response.
以上端口设置都是80 是不是请求包设置错误了 至少代理User-Agent:选项应该是linux的 但我认为这个没有影响?求指点
{
char* buf = (char*)malloc(1024*4);
strcat(buf, "GET /");
strcat(buf, " HTTP1.1rn");
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, */*rn");
strcat(buf,"Accept-Language: zh-cnrn");
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)rn");
strcat(buf,"Host:");
strcat(buf,url);
strcat(buf,"rn");
strcat(buf,"Connection:Keep-Alive rn");
strcat(buf,"rn");
printf("%sn",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
502 Bad Gateway
The server returned an invalid or incomplete response.
以上端口设置都是80 是不是请求包设置错误了 至少代理User-Agent:选项应该是linux的 但我认为这个没有影响?求指点
|
GET / HTTP/1.1