#include
#include
#include
#pragma comment(lib, “ws2_32.lib”)
void geturl(char *url)
{
WSADATA WSAData={0};
SOCKET sockfd;
struct sockaddr_in addr;
struct hostent *pURL;
char myurl[BUFSIZ];
char *pHost = 0, *pGET = 0;
char host[BUFSIZ], GET[BUFSIZ];
char header[BUFSIZ] = “”;
static char text[BUFSIZ];
int i;
/*
* windows下使用socket必须用WSAStartup初始化,否则不能调用
*/
if(WSAStartup(MAKEWORD(2,2), &WSAData))
{
printf(“WSA failedn”);
return;
}
/*
* 分离url中的主机地址和相对路径
*/
strcpy(myurl, url);
for (pHost = myurl; *pHost != ‘/’ && *pHost != ‘