I once began writing a class for http packets using winsocks... It's probably bad, but it should give you an idea on how to start.
Code:
#pragma comment(lib, "Ws2_32.lib")
#include <Windows.h>
#include <iostream>
#include <string>
#include <sstream>
class packet
{
private:
int Socket;
char* buf;
int size;
sockaddr_in service;
public:
packet(bool pPost, string pLocation, string pHost);
bool Post;
string Location;
string Host;
string Send();
~packet();
};
packet::packet(bool pPost, string pLocation, string pHost)
{
Post = pPost;
Location = pLocation;
Host = pHost;
WSADATA w;
WSAStartup(MAKEWORD(2,2), &w);
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
service.sin_family = AF_INET;
service.sin_port = htons(80);
service.sin_addr.s_addr = inet_addr("127.0.0.1"); // IP
};
string packet::Send()
{
string Request;
if (Post == true) // incomplete
{
Request += "POST ";
}
else
{
Request += "GET ";
}
Request += Location + " HTTP/1.1\r\n";
Request += "Host: " + Host + "\r\n";
Request += "Connection: close\r\n\r\n";
unsigned int bytesSent = 0;
connect(Socket, reinterpret_cast<sockaddr*>(&service), sizeof(service));
do
{
bytesSent += send(Socket, Request.c_str() + bytesSent, Request.size() - bytesSent, 0);
} while(bytesSent < Request.size());
string Response;
char ReceivedBytes[256];
int BytesReceived = 1;
while(BytesReceived > 0)
{
BytesReceived = recv(Socket, ReceivedBytes, sizeof(ReceivedBytes), 0);
Response.append(ReceivedBytes, BytesReceived);
}
return Response;
};
packet::~packet()
{
closesocket(Socket);
WSACleanup();
};