I made this class because I needed to post some data to an ASP page. There are functions for getting a webpage, posting to a webpage, and getting the headers and the server status code. The class also works with Unicode. I have written the class using WinInet, so you have to link with wininet.lib.
Just make a new instance of the class, like:
GetPage() receives a webpage, or posts data to it.
char* GetPage(const TCHAR *url, bool Post = false,
const char *PostData = NULL, int PostDataLength = -1);
To simply receive a page just write:
char *s = http.GetPage(_T("http://somewebpage/");
Post indicates whether you want to perform a HTTP POST or GET.
PostData is the data you want to post to the webpage. This parameter is a
char* because you cannot post Unicode strings. If
NULL terminated, just leave
PostDataLength as it is, else
PostDataLength is the length of the
If you want to post some data, that is a
NULL terminated string, just write:
char *s = http.GetPage(_T("http://somewebpage/", true, "Some Data To Post");
If you just want to get the headers for a webpage you van use
TCHAR* GetHeaders() to receive those.
TCHAR *ts = http.GetHeaders(_T("http://somewebpage/");
If you want to get the HTTP status code after you have received a webpage, or posted to one, just call
int i = http.GetPageStatusCode();
i contains the status code, like "404" if the page doesn't exists.
Well, that's all there is to it, hope you find it useful.