I have the next code to make a connection to my website:
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#include <WinSock2.h>
#include <WS2tcpip.h>
#include "Client.h"
#include <iostream>
#pragma comment(lib, "Ws2_32.lib")
void WSAStartup()
{
// This will lead us all the way long...
int Errors;
WSADATA wsadata;
Errors = WSAStartup(MAKEWORD(2, 2), &wsadata);
if (Errors != 0)
{
std::cout << "E1, " << Errors << ".\n";
getchar();
exit(1);
}
//---------------------------------------
}
int main()
{
WSAStartup();
Client http_client;
http_client.ZeroMem();
http_client.GetInfo("www.xxx.xxx.xxx", "http"); // "http" is like writing 80. can be also integer parameter.
http_client.CreateSocket();
if (!http_client.Connect()) // If true, so it means there all went well.
{
std::cout << "Good for us! We are in.\n";
}
http_client.Recv();
http_client.~Client();
std::cin.get();
return 0;
}
In the header "Client.h" I did all the "dirty staff"... I get the next output:
Good for us! We are in.
So apparently the problem is not the coding. I thought when I makes a connetion of "http" with a website, so the first thing I get in response is a DATA from the website containing the all html code of the index page, buy it doesnt.
I run this program while 'Wiresharking' to see what I get between the SYN till the FIN, here is the screenshot of what I got:
Screenshot of wireshark while runing my code
There isnt any DATA I get back as you can see... So how exactly should I work with sockets in cpp when I ask (or send a post request) html data? Links will be appreciated. thanks.