Click here to Skip to main content
6,634,665 members and growing! (15,013 online)
Email Password   helpLost your password?
General Programming » Internet / Network » HTTP / HTTPS     Intermediate

AmHttpUtilities

By Anders Molin

A small class that handles HTTP POST, GET and HEAD operations.
VC6Win2K, Visual Studio, MFC, Dev
Posted:3 Sep 2001
Views:144,648
Bookmarked:52 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
35 votes for this article.
Popularity: 6.24 Rating: 4.04 out of 5
2 votes, 8.3%
1

2
2 votes, 8.3%
3
5 votes, 20.8%
4
15 votes, 62.5%
5

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


Member
Huh! Wink
Occupation: Software Developer (Senior)
Location: Denmark Denmark

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 63 (Total in Forum: 63) (Refresh)FirstPrevNext
GeneralGetPageStatusCode need GetHeaders [modified] PinmemberKikoa5:25 17 Sep '07  
GeneralPosting Problens PinmemberJot Singh6:27 13 Jun '07  
GeneralRe: Posting Problens PinmemberAlbertino11:54 11 Aug '07  
GeneralCookie Support Pinmembermhecker7:36 29 Dec '06  
QuestionHow to check if the data is successfully posted or not [modified] PinmemberAdeel6882:17 7 Aug '06  
Generalhow to use proxy? Pinmembershellhy23:13 7 Jun '06  
AnswerRe: how to use proxy? PinmemberDavidA20053:47 5 Mar '09  
GeneralHow to Post XML - Data? PinmemberGenerator3Punkte0:21 6 Apr '06  
GeneralRe: How to Post XML - Data? Pinmembervijicode2:09 22 Nov '06  
Newsnot thread-safe Pinmemberindrekm2:13 15 Dec '05  
GeneralHandling SSL certificates errors PinmemberOrkblutt22:36 18 Oct '05  
Questionmemory leak? Pinmemberdark dog12:16 9 Sep '05  
AnswerRe: memory leak? Pinmemberdietox11:19 24 Sep '07  
GeneralProblem :) Pinsusszaixx12:27 7 Jul '05  
GeneralRe: Problem :) Pinmemberdietox4:08 6 Oct '07  
GeneralProblem including header Pinmemberint01h12:00 24 Jun '05  
GeneralRe: Problem including header PinsussAnonymous12:45 24 Jun '05  
GeneralTransfer Unicode data PinmemberSitaram Sukumar21:04 3 Feb '05  
Generalgood work Pinmembermotosir5:47 7 Aug '04  
GeneralGreat! PinmemberTodd.Harvey9:34 2 Mar '09  
Generalto save the web page without opening in a browser Pinmemberdu_aa20:44 1 Dec '03  
GeneralVery Nice code...But PinmemberSumit Kapoor1:56 20 Nov '03  
GeneralRe: Very Nice code...But Pinmembery_yy200817:13 10 Dec '08  
GeneralRe: Very Nice code...But PinmemberSumit Kapoor14:02 12 Dec '08  
GeneralMod PinmemberBaldcat19:49 1 Oct '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Sep 2001
Editor: Smitha Vijayan
Copyright 2001 by Anders Molin
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project