WSADATA wData;
::WSAStartup(MAKEWORD(2, 2), &wData);
SOCKET clientSocket = socket(AF_INET, 1, 0);
struct sockaddr_in ServerAddr = { 0 };
int Ret = 0;
int AddrLen = 0;
HANDLE hThread = 0;
int len = 0;
CString Lenthstr;
char HexLength[20];
int Hexlen = 0;
CString temp = _T("");
temp = "GET "+url+" HTTP/1.1\r\n";
temp += "host:" + ip + ":"+port+"\r\n\r\n";
//temp += "Accept:image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/x-shockwave-flash,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,*/*\n";
//temp += "Accept-Language: zh-cn\n";
//temp += "User-Agent:iPanelBrowser/2.0\n";
//temp += "host:" + ip + ":" + "7001\n";
//temp += "Connection:close\n\n";
//char tempbuf[1024] = "Get";
//char tempbuf[1024] = "Get /check?+参数 HTTP/1.1\r\nConnection:Keep-Alive\r\nAccept-Encoding:gzip, deflate\r\nAccept-Language:zh-CN,en,*\r\n";
//temp = tempbuf;
//temp += "host:" + url + "\r\n" + "User-Agent:Mozilla/5.0\r\n\r\n";
IWriteLog(temp);
char bufSend[1024] = {0};
strcpy(bufSend,temp);
//FILE *fpt;
//fpt = fopen("d://wendangming.txt", "a+");//打开文档,写入
//char addIp[256] = { 0 };
//GetIpByDomainName("www.baidu.com", addIp);
ServerAddr.sin_addr.s_addr = inet_addr(ip);
ServerAddr.sin_port = htons(atoi(port));
int errNo = 0;;
ServerAddr.sin_family = AF_INET;
char bufRecv[6069] = { 0 };
errNo = connect(clientSocket, (sockaddr*)&ServerAddr, sizeof(ServerAddr));
if (errNo == 0)
{
//如果发送成功,则返回发送成功的字节数;
if (send(clientSocket, bufSend, strlen(bufSend), 0)>0)
{
//cout << "发送成功\n";;
}
else
{
errNo = WSAGetLastError();
return FALSE;
}
Sleep(1000);
//如果接受成功,则返回接受的字节数;
if(len = recv(clientSocket, bufRecv, 6069, 0)>0)
{
//cout << "接受的数据:" << bufRecv << endl;
m_Return = bufRecv;
//Hexlen = m_Return.GetLength();
len = m_Return.Find("true");
if (len > 0)
{
Lenthstr = m_Return.Mid(len - 4, 2);
strcpy(HexLength, Lenthstr);
Hexlen = strtol(HexLength, NULL, 16);
m_Return = m_Return.Mid(len + 5, Hexlen - 5);
return TRUE;
}
else
{
m_error = 5000;
GetCurrentError(m_error);
return FALSE;
}
//len = strlen(bufRecv);
//fwrite(bufRecv, 1, sizeof(bufRecv), fpt);
////fprintf(fpt,bufRecv);
// //n++;
//fclose(fpt);
}
}
else
{
m_error = 5000;
GetCurrentError(m_error);
return FALSE;
}
//socket环境清理;
closesocket(clientSocket);
::WSACleanup();