实例:
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<errno.h>
#include<stdlib.h>
#include <netdb.h>
#include <string.h>
int main()
{
int sockfd;
struct sockaddr_in sin;
struct hostent *ht;
char GETPAGE[] = "GET /chinabhlt/article/details/43670871 HTTP/1.1\nHost:blog.csdn.net\n\n";
char bufpage[100000];
if((ht = gethostbyname("blog.csdn.net")) == NULL)
{
perror("no website");
return -1;
}
//printf("host:%s\n", ht->h_name);
sin.sin_port = htons(80);
sin.sin_addr.s_addr = *(unsigned long*)ht->h_addr_list[0];
sin.sin_family = AF_INET;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))<0)
{