Ethien
asked on
C++ winsocking
Hello, I'm trying to learn winsock so I could send a get http request to a desired hostname. I know how to setup a socket and start up Winsock but I do not know how to send a Get request to a website. Could someone explain this?
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main()
{
char version[3];//Setup version
version[0]='1';//use version 1.1
version[2]='1';
string display_version="1.1";
SOCKET MySocket;
WSADATA info;
cout<<"Loading Winsock Version: "<<display_version<<endl;
if (WSAStartup(MAKEWORD(version[0],version[2]),&info) != 0)
{
cout<<"Cannot initialize WinSock!\nError: "<<WSAGetLastError()<<"\nCleaing up!"<<endl;
WSACleanup();
return -1;
}
if(WSAStartup(MAKEWORD(version[0],version[2]),&info) == 0)
{
cout<<"Winsock initialzed!\nVersion "<<display_version<<endl;
cout<<"Initialzing socket..\n";
MySocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(MySocket == INVALID_SOCKET)
{
cout<<"Invalid socket decalred!";
WSACleanup();
}
cout<<"Socket initialzed!\n";
}
system("PAUSE");
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The first get in the sentence should be send.