httpdump.cpp

This code asks for a document path, then connects to a webserver and retrieves through a GET request;

00001 #include <iostream>
00002 #include <string>
00003 #include <socklibpp/sockstream.h>
00004 
00005 using namespace std;
00006 using namespace socklibpp;
00007 
00008 int main()
00009 {
00010         string hostn, doc = "/";
00011         cout << "Enter the host address: " << flush;
00012         if (!(cin >> hostn))
00013                 return -1;
00014         
00015         cout << "Enter the document location (e.g. '/', 'index.html'): ";
00016         cin >> doc;
00017         
00018         sockstream web;
00019         if (!web.connect(hostn.c_str(), 80)) {
00020                 cerr << "Host not found" << endl;
00021                 return -1;
00022         }
00023         
00024         web << "GET " << doc << " HTTP/1.0" << crlf;
00025         web << crlf;
00026         
00027         // Now read the response
00028         string response;
00029         while (getline(web, response))
00030                 cout << response << endl;
00031 
00032 }

Generated on Thu Jan 18 19:26:34 2007 for socklib++ by  doxygen 1.5.1