
Introduction
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 = "www.yoursite.com";
CWebAccess webAccess;
webAccess.Get(url, result);
In order to POST to an HTTP page, the following code can be used:
CString url, urlData, result;
url = "www.yoursite.com/blahblah.php";
urlData = "someparam=somevalue&someparam2=somevalue2";
CWebAccess webAccess;
webAccess.Post(url, urlData, result);
Points of Interest
Take a look at GET and POST functions, and also how the callback is handled.
History
This is the first version, as soon as I get some time for me, I'll complete the tutorial.