当前位置: 技术问答>linux和unix
linux c socket编程抓取网页的问题
来源: 互联网 发布时间:2017-03-18
本文导语: 最近在学习linux的网络编程,从网上找了分抓取网页的代码,但是不知为什么不能够获取整个网页 代码如下: [code=C/C++] [#include #include #include #include #include #include #include #define HTTPPORT 80 char *head = "GET /...
最近在学习linux的网络编程,从网上找了分抓取网页的代码,但是不知为什么不能够获取整个网页
代码如下:
[code=C/C++]
[#include
#include
#include
#include
#include
#include
#include
#define HTTPPORT 80
char *head = "GET /about HTTP/1.1rn"
"Accept: */*rn"
"Accept-Language:zh-cnrn"
"Accept-Encoding:gzip,deflatern"
"Host:www.ietf.orgrn"
"Connection:Keep-Alivernn";
int connect_URL(/tech-qa-linux/char _domain,int port/index.html)
{
int sock;
struct hostent *host;
struct sockaddr_in server;
host = gethostbyname(domain);
if(host == NULL)
{
printf("gethostbyname errorn");
return -2;
}
sock = socket(AF_INET,SOCK_STREAM,0);
if(sock h_addr_list[0],host->h_length);
server.sin_family = AF_INET;
server.sin_port = htons(port);
if(connect(sock,(struct sockaddr *) &server,sizeof(struct sockaddr))
代码如下:
[code=C/C++]
[#include
#include
#include
#include
#include
#include
#include
#define HTTPPORT 80
char *head = "GET /about HTTP/1.1rn"
"Accept: */*rn"
"Accept-Language:zh-cnrn"
"Accept-Encoding:gzip,deflatern"
"Host:www.ietf.orgrn"
"Connection:Keep-Alivernn";
int connect_URL(/tech-qa-linux/char _domain,int port/index.html)
{
int sock;
struct hostent *host;
struct sockaddr_in server;
host = gethostbyname(domain);
if(host == NULL)
{
printf("gethostbyname errorn");
return -2;
}
sock = socket(AF_INET,SOCK_STREAM,0);
if(sock h_addr_list[0],host->h_length);
server.sin_family = AF_INET;
server.sin_port = htons(port);
if(connect(sock,(struct sockaddr *) &server,sizeof(struct sockaddr))