5,401,186 members and growing! (19,360 online)
Email Password   helpLost your password?
Web Development » Internet / Network » HTTP / HTTPS     Intermediate

AmHttpUtilities

By Anders Molin

A small class that handles HTTP POST, GET and HEAD operations.
VC6, C++Windows, NT4, Win2K, Visual Studio, MFC, Dev

Posted: 3 Sep 2001
Updated: 3 Sep 2001
Views: 120,137
Bookmarked: 44 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
35 votes for this Article.
Popularity: 6.24 Rating: 4.04 out of 5
2 votes, 8.3%
1
0 votes, 0.0%
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


Huh!

Occupation: Web Developer
Location: Denmark Denmark

Other popular Internet / Network articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 59 (Total in Forum: 59) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralGetPageStatusCode need GetHeaders [modified]memberKikoa5:25 17 Sep '07  
GeneralPosting ProblensmemberJot Singh6:27 13 Jun '07  
GeneralRe: Posting ProblensmemberAlbertino11:54 11 Aug '07  
GeneralCookie Supportmembermhecker7:36 29 Dec '06  
QuestionHow to check if the data is successfully posted or not [modified]memberAdeel6882:17 7 Aug '06  
Generalhow to use proxy?membershellhy23:13 7 Jun '06  
GeneralHow to Post XML - Data?memberGenerator3Punkte0:21 6 Apr '06  
GeneralRe: How to Post XML - Data?membervijicode2:09 22 Nov '06  
Newsnot thread-safememberindrekm2:13 15 Dec '05  
GeneralHandling SSL certificates errorsmemberOrkblutt22:36 18 Oct '05  
Questionmemory leak?memberdark dog12:16 9 Sep '05  
AnswerRe: memory leak?memberdietox11:19 24 Sep '07  
GeneralProblem :)susszaixx12:27 7 Jul '05  
GeneralRe: Problem :)memberdietox4:08 6 Oct '07  
GeneralProblem including headermemberint01h12:00 24 Jun '05  
GeneralRe: Problem including headersussAnonymous12:45 24 Jun '05  
GeneralTransfer Unicode datamemberSitaram Sukumar21:04 3 Feb '05  
Generalgood workmembermotosir5:47 7 Aug '04  
Generalto save the web page without opening in a browsermemberdu_aa20:44 1 Dec '03  
GeneralVery Nice code...ButmemberSumit Kapoor1:56 20 Nov '03  
GeneralModmemberBaldcat19:49 1 Oct '03  
Generalabout deconstructor functionsussbsongo17:09 25 Aug '03  
GeneralDoes it work if a client connect to Internet via a proxy server?susszxmhxj22:01 28 Jul '03  
GeneralRe: Does it work if a client connect to Internet via a proxy server?memberHung-bin Chen19:10 6 Oct '03  
GeneralRe: Does it work if a client connect to Internet via a proxy server?sussAnonymous0:53 4 May '04  

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-2008
Web15 | Advertise on the Code Project