Click here to Skip to main content
15,121,963 members
Articles / Desktop Programming / MFC
Posted 13 Mar 2005


49 bookmarked

WinInet wrapper class to handle HTTP GET/POST, Part 1

Rate me:
Please Sign up or sign in to vote.
3.53/5 (11 votes)
13 Mar 20051 min read
A simple class to handle HTTP GET and POST.

Sample Image


I've been using Heo's class for HTTP POST and GET, however, I noticed that my POST commands were failing randomly. It turned out that in his class, GenericHTTPClient::RequestPostMultiPartsFormData fails unless we open up the browser and send the post request there. Now, it may be just me who was getting this error but it was really annoying. So I wrote my own class to handle HTTP POST/GET and downloading etc. This article is the first part of a series of articles in which I plan to explain the entire process of using WinInet (actually, you can use this code as a preface to the series of articles, since the class supports GET and POST only!). Another difference between my class and others is that it completely wraps the process of adding parameters when posting an HTTP request. All you need to do is pass your data as param=value¶m2=value2 etc., just like you would do for your GET request.

Using the code

In order to GET an HTTP page, the following code can be used:

CString url, result;
url = "";

// Create object of class
CWebAccess webAccess;

// get the result
webAccess.Get(url, result);

In order to POST to an HTTP page, the following code can be used:

CString url, urlData, result;
// url is url of the site, urlData is data, and result contains result.

url = "";
urlData = "someparam=somevalue&someparam2=somevalue2";

// create CWebAccess object
CWebAccess webAccess;
// send request
webAccess.Post(url, urlData, result);

// do whatever you want with result.

Points of Interest

Take a look at GET and POST functions, and also how the callback is handled.


This is the first version, as soon as I get some time for me, I'll complete the tutorial.


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

Uraan Software Solutions
Founder Uraan Software Solutions
Germany Germany
We are a software development and consultancy firm based in Lahore, Pakistan.

Comments and Discussions

QuestionApplicable license? Pin
Member 94255011-Sep-13 10:37
MemberMember 94255011-Sep-13 10:37 
Generalafx.h: No such file or directory Pin
sawer520-Feb-11 9:53
Membersawer520-Feb-11 9:53 
QuestionPorts ??? Pin
Peggy Van Lierde5-Jun-08 23:15
MemberPeggy Van Lierde5-Jun-08 23:15 
Questionit doesn't seem to work on https posting xml data Pin
dragonmc12-Sep-07 12:36
Memberdragonmc12-Sep-07 12:36 
GeneralThe system cannot find the file specified. Pin
berilium10-Jul-07 14:54
Memberberilium10-Jul-07 14:54 
GeneralUnicode string Pin
Timaeus.W.T30-Dec-06 3:48
MemberTimaeus.W.T30-Dec-06 3:48 
GeneralPOST Operation Not working [modified] Pin
Adeel6887-Aug-06 21:18
MemberAdeel6887-Aug-06 21:18 
GeneralMemory Leak Pin
RedFraggle11-Mar-06 14:33
MemberRedFraggle11-Mar-06 14:33 
GeneralRe: Memory Leak Pin
Lars [Large] Werner2-Sep-06 15:35
professionalLars [Large] Werner2-Sep-06 15:35 
GeneralRe: Memory Leak Pin
jacksp4-Sep-11 18:35
Memberjacksp4-Sep-11 18:35 
GeneralProxy authorization Pin
jprieto23-Dec-05 1:42
Memberjprieto23-Dec-05 1:42 
GeneralRe: Proxy authorization Pin
Stephenjpmurphy4-Dec-07 23:59
sussStephenjpmurphy4-Dec-07 23:59 
Generalerror detecting proxy settings Pin
Kostya268316-Sep-05 6:59
MemberKostya268316-Sep-05 6:59 
GeneralGood Program. Piece of code that actvates send button. Pin
pr_00110-Aug-05 17:35
Memberpr_00110-Aug-05 17:35 
GeneralHi your app is good but I wonder something Pin
Acronia4-Jul-05 21:39
MemberAcronia4-Jul-05 21:39 
GeneralErr code 122 Pin
daveice20-Mar-05 18:01
Memberdaveice20-Mar-05 18:01 
Generalnice program Pin
Tom Krenn17-Mar-05 9:09
sussTom Krenn17-Mar-05 9:09 

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

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