Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

AmHttpUtilities

0.00/5 (No votes)
3 Sep 2001 2  
A small class that handles HTTP POST, GET and HEAD operations.

Introduction

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:

CAmHttpSocket http;

The function 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/");

The 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 PostData is NULL terminated, just leave PostDataLength as it is, else PostDataLength is the length of the PostData buffer.

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 GetPageStatusCode() like:

int i = http.GetPageStatusCode();

Now 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here