Click here to Skip to main content
Licence 
First Posted 3 Sep 2001
Views 197,603
Bookmarked 61 times

AmHttpUtilities

By | 3 Sep 2001 | Article
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

About the Author

Anders Molin

Software Developer (Senior)

Denmark Denmark

Member

Huh! Wink | ;-)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralGetPageStatusCode need GetHeaders [modified] PinmemberKikoa4:25 17 Sep '07  
GeneralRe: GetPageStatusCode need GetHeaders Pinmemberkamplus21:57 23 Feb '11  
GeneralPosting Problens PinmemberJot Singh5:27 13 Jun '07  
GeneralRe: Posting Problens PinmemberAlbertino10:54 11 Aug '07  
GeneralCookie Support Pinmembermhecker6:36 29 Dec '06  
QuestionHow to check if the data is successfully posted or not [modified] PinmemberAdeel6881:17 7 Aug '06  
Questionhow to use proxy? Pinmembershellhy22:13 7 Jun '06  
AnswerRe: how to use proxy? PinmemberDavidA20052:47 5 Mar '09  
QuestionHow to Post XML - Data? PinmemberGenerator3Punkte23:21 5 Apr '06  
AnswerRe: How to Post XML - Data? Pinmembervijicode1:09 22 Nov '06  
Newsnot thread-safe Pinmemberindrekm1:13 15 Dec '05  
GeneralHandling SSL certificates errors PinmemberOrkblutt21:36 18 Oct '05  
Questionmemory leak? Pinmemberdark dog11:16 9 Sep '05  
AnswerRe: memory leak? Pinmemberdietox10:19 24 Sep '07  
GeneralProblem :) Pinsusszaixx11:27 7 Jul '05  
GeneralRe: Problem :) Pinmemberdietox3:08 6 Oct '07  
GeneralProblem including header Pinmemberint01h11:00 24 Jun '05  

D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2061: syntax error : identifier 'CAmHttpSocket'
D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2059: syntax error : ';'
D:\C\ALLEGRO\WWW/amhttpsocket.h(14) : error C2449: found '{' at file scope (missing function header?)
D:\C\ALLEGRO\WWW/amhttpsocket.h(29) : error C2059: syntax error : '}'
 

It looks like there is something wrong with the class ?
GeneralRe: Problem including header PinsussAnonymous11:45 24 Jun '05  
GeneralTransfer Unicode data PinmemberSitaram Sukumar20:04 3 Feb '05  
Generalgood work Pinmembermotosir4:47 7 Aug '04  
GeneralGreat! PinmemberTodd.Harvey8:34 2 Mar '09  
Generalto save the web page without opening in a browser Pinmemberdu_aa19:44 1 Dec '03  
GeneralVery Nice code...But PinmemberSumit Kapoor0:56 20 Nov '03  
GeneralRe: Very Nice code...But Pinmembery_yy200816:13 10 Dec '08  
GeneralRe: Very Nice code...But PinmemberSumit Kapoor13:02 12 Dec '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 4 Sep 2001
Article Copyright 2001 by Anders Molin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid