Working with WinHTTP, totally lost

For starters, I'm a rank amateur. I accept this. My education in C++ was 1 class and about 100 hours of goofing around with coding before I got into education instead of programming. That being said, I still put C++ training on my resume and my current job actually decided to utilize it (ack!) They know my limited experience and mostly just want me to try (discount programming at its finest I guess.)

That out of the way, here is what I need to do. They want a program that gathers data off a server and displays it on a screen. The displaying I'm fine with (not that much of an amateur) but I'm struggling getting the data to begin with because I've never worked with HTTP.

I've been told that C++ isn't the best program for this but its the only one I know well enough to even try. My research tells me that using WINHTTP is the best way to go but online resources into this are scarce.

Here is the HTTP code I was given by the company that hosts this data:

GET /download?start-date=0000-00-00&end-date=0000-00-00 HTTP/1.1
Host: (their server name)
Authorization: Basic (a 20 digit string of letters, numbers, and symbols)

The HTTP authentication header also needs to include my username and site-download-key and I don't even know how to do that.

I figure that while I pounded away at this (my headaches keep Ibuprofen companies the world over funded) I could make an unreasonable request of you guys and ask if anybody knows how to translate all that over from standard HTTP to WINHTTP AND enable Visual Studio 2010 to utilize WINHTTP.

Please, help.
Why HTTP? Does it have to face the outside world? Or can external users use VPN to connect to the machine itself instead of having to make it face the outside world through HTTP?
I believe it does have to utilize HTTP. The code I gave you is the code given to the company I work for to access that server.

They collect data from meters we place that we can access but we want to create a live (or at least regularly updated) display in our operations department. When we talked to them about getting that data they gave us the HTTP code I posted as the means to access it outside of their website.

I VPN can work I'm interested in learning it (never even heard of it to be frank.)
If you use libcurl all you need to write is few lines of code and you are almost done (basic authentication is supported too):

libcurl is a portable library and widely used by many applications, unless winhttp.
I've considered libcurl but I can't even seem to get it installed. I'm using Visual C++ Express and none of the directions seem to make sense. Admittedly, that may be because of the flu and pulsing migraine I'm fighting off. Not a good week.
IMHO, and keep in mind I love C++, saying that it isn't the best tool for this job is like saying that a pocket knife isn't the best tool to pound in a nail. Not that C++ can't do this, but FTP (this one is a protocol not a language), Java, .Net, C#, Java Script and even HTTP itself do it so much better. I honestly see nothing but pain for you in this project and nothing against you but the best result you could hope for would probably be sub-par.

Does your company have an M$ Exchange Server and\or SharePoint? Do you have an established FTP server? There has to be an easier way.

To answer your question about how to get WinHTTP to work you should download the MS SDK from here in the top left corner to make sure you have it: and link to Wininet.lib after you unpack it into your IDE's directory to make linking to it a bit easier. Gathering the data would be highly dependent on how the data is being output from the meters.

One more attempt to talk you out of this and then I'm done I promise. Is this something that Nagios would be better solution for?
Last edited on
I appreciate your input Computergeek01, and I would take it if I could, but it appears I've got to press forward with the tools I have. This is just going to have to be amateur hour (sub-par work is my specialty.)

I have decided to utilize libcurl (it just looks easier) but I'm having trouble installing it. A few website have helped me struggle through but when I try to use nmake makefile.vc10 in the VS Command Prompt it tells me that it can't open liburl.lib because link.exe can't find a .dll that is on the computer. Other websites tell me that I need to add the path to this but I can't find a way to do that (this installation seems fairly automated.)

Does anybody know what I'm doing wrong or where I can find a tutorial or somesuch to help get this installed?
I worked with winhttp, and I ended up creating a reasonable wrapper. But I remember the same issue: no easy to understand online resources. (The MSDN winhttp documentation cannot be considered easy to understand!)

You might consider winsock. It seems both lower level than winhttp and also more commonly used - and hence with more online help.

In any case, the first thing to do is understand http. Everything becomes easier after that.

(My personal experience was to watch out for NULL characters in your http message - if you are sending files with NULL characters in, make sure you do not store the files in NULL terminated strings.)

I am not sure I agree with the idea that c++ is not a good tool for http. The question is whether you really want exposure to http, or if you want to deal with it through some simplifying medium.

Topic archived. No new replies allowed.