1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <string>
//#pragma comment(lib,"ws2_32.lib")
using namespace std;
int main (){
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
cout << "WSAStartup failed.\n";
system("pause");
return 1;
}
SOCKET Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
struct hostent *host;
host = gethostbyname("abcd.abcd.net");
SOCKADDR_IN SockAddr;
SockAddr.sin_port=htons(80);
SockAddr.sin_family=AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
// cout << "Connecting...\n";
if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0){
cout << "Could not connect";
system("pause");
return 1;
}
// cout << "Connected.\n";
string sendbuf = "GET /met.php HTTP/1.1\r\nHost: abcd.abcd.net\r\nConnection: close\r\n\r\n";
send(Socket,sendbuf.c_str(), sendbuf.length(), 0);
char buffer[10000];
string buff;
int nDataLength = 1;
while (nDataLength != 0)
{
buffer[0] = 0;
nDataLength = recv(Socket,buffer,10000,0);
buff.append (buffer, nDataLength);
//cout << buffer;
}
closesocket(Socket);
WSACleanup();
cout << buff;
system("pause");
return 0;
}
|