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 60 61
|
#include <iostream>
#include <sstream>
#include "TCPSocket.h"
using namespace std;
int main()
{
try
{
cout << "HTTP REQUEST" << endl;
cout << "------------" << endl;
// Establecemos la conexion con el servidor
TCPSocket *tcpSocket = new TCPSocket();
tcpSocket->Connect("www.ubuntu.com", 80);
// Generamos la peticion HTTP
stringstream request;
request << "HEAD / HTTP/1.1\r\n";
request << "Host: www.ubuntu.com\r\n";
request << "User-agent: My User Agent for Test 1, ";
request << "My User Agent for Test 2, ";
request << "My User Agent for Test 3, ";
request << "My User Agent for Test 4, ";
request << "My User Agent for Test 5, ";
request << "My User Agent for Test 6, ";
request << "My User Agent for Test 7, ";
request << "My User Agent for Test 8, ";
request << "My User Agent for Test 9, ";
request << "My User Agent for Test 10, ";
request << "My User Agent for Test 11, ";
request << "My User Agent for Test 12, ";
request << "My User Agent for Test 13, ";
request << "My User Agent for Test 14, ";
request << "My User Agent for Test 15, ";
request << "My User Agent for Test 16, ";
request << "My User Agent for Test 17";
request << "\r\n";
request << "\r\n";
// Realizamos la peticion HTTP
tcpSocket->Write(request.str().c_str());
// Obtenemos la respuesta del servidor
char *data = tcpSocket->Read();
string response = string(data);
cout << endl << response << endl;
delete tcpSocket;
return (0);
}
catch (const char *e)
{
cout << "Excepcion: " << e << endl;
return (-1);
}
}
|