Link to home
Start Free TrialLog in
Avatar of Ethien
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;
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rahul_r_jadhav
rahul_r_jadhav

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwb178
dwb178

The first get in the sentence should be send.