Http + C++

I want to send an http request for a file from within c++. Specifically, i want to request a picture (i know the file name before hand), and i want to do it often. In fact, i dont even want the picture, i just want to be able to ask for it. Well, it would be nice to actually be able to see the pic, but really all i am trying to do is see if the file still exists. any help would be much appreciated.

I looked through the MSDN and then promptly slapped myself for the silly waste of effort. Why in the sam hill would i want to use an MFC class that is the third wrapper placed around a set of functions?

One way to do this would be with the InternetOpenURL function. Unfortunately, this function will immediately start downloading the requested file, and I don’t remember any options to disable this feature. Since you have the MSDN library, I won’t post all the details of this function here, since it is rather long.

If anyone familiar with the inner workings of the HTTP protocal could let us know if there is a command to query whether a file exists or not, you can use the HttpSendRequest function to send a customized set of headers.

Anyway, C++ doesn’t provide networking capability as part of the language, so you’re going to have to use either MFC or the Platform SDK. Alternatively, Java sounds like a much better solution to this problem, but I could be wrong. Could you post a few more details about what it is you are trying to do?

Finally, please don’t bash MFC and the MSDN library. RoboEmu was written completely in MFC and it helped so much in the development process I can’t imagine ever going back. Likewise, a LOT of commercially produced software, including PTC’s Pro/Desktop, uses MFC. If you’ve ever tried designing a GUI with more than a few elements, especially if it uses custom controls, you’ll learn to appreciate the incredible power and simplicity of MFC.

The HTTP 1.1 RFC should help just a tad.

I could help more if I had my documents…I’m not at home right now. And it’s freaking 1:30am :slight_smile:

We used something like this for our picture archiving program for AP Computer Science class (it basically searches a directory for specified picture files and archives them. It also inputs internet pictures, with link validating. Lastly, it can output the pictures in random slideshow format)… It was me and another person’s final project… :smiley: :smiley:

That’s the program, source included. You need the HTTP.h file…

Then the commands you should be able to look at the source in archiver.cpp. It’s the linkchecker() function. Just replace the apstring types with c string types. Actually, that’s what it’s doing…

apstring temp = archive*.locout();

const char* url = temp.c_str();

and the rest of the function uses “url” (to stay compatible from that APSTRING crap).*

sorry about the MFC bashing. It is just that i looked at DirectPlay, and then at winsock to do multiplayer type stuff. If you have never seen DirectPlay code, give your self a pat on the back, for you have stayed on the path of light. To open a DirectPlay game, it requires 40 pages of code. To start a winsock game, the networking bit is maybe 2 pages. Then i compared DirectX with glut, and it was the same. And then mfc’s music / sound stuff with fmod ( is a great site if you want sound in your apps). Every time i look at the microsoft way of doing it, i want to puke. I’ll admit that I have never really given it a fair chance, and that their must be a reason that they sell so much stuff, but I really don’t like their methods, or at least the methods that i have seen from them.

Any way…
Thanks for all the help. I thought about doing it in java, but i have no experience with the language. Should I teach myself Java? My school is begining this year to offer it, and i am always in the room they do it in… But I don’t want to confuse it with C.

Ill check out those links as soon as i am on a computer.
Mine is making jackhammer noises that would scare small children, and would prompt exorcism if i was more religious.

Thanks again

Please don’t confuse MFC with DirectX. DirectX lets you access hardware for games, multimedia, etc. MFC creates a user interface for you. It handles all the dialog box, menu, button, etc message passing for you; all you do is supply the code to run when it finally receives one of those messages.

As for learning Java, go for it. The more languages you know, the better. Also, most Computer Science degree programs are Java-based now. Anytime you want to do anything with networking, graphics, or multimedia, Java simplifies the task immensely. Besides, the AP CSci test is moving to Java for May 2004 tests.

I understand clearly the difference: It is just that both are by the same company and both give me the same throbbing headache.

Due to your advice, I will sign up for Java, unless you happen to know where i can find some intuitive books or tuts on the subject. I have several friends who are proficient in the language, so I would be able to ask for help when I need it.

Lastly, what language is your favorite? You seem to be able to crank out code faster than anyone i know. Is this due to some secret dietary regimen or some form spiritual cleansing ritual? I know I talk like a total newb, but forgive my transgressions as I will forgive yours (if I ever find one of yours)

Ironically, my speed is because of MFC. Yes, you read that right. For example, RoboCon, which I started Friday night and finished this morning, took about 10 hours of work. With MFC, only about 45 minutes were spent on the UI.

As for my language of choice, I mostly do C/C++. I say both because I don’t ever write in “pure” C++. For example, I absolutely hate class String, so I use char * and printf, sprintf, etc. Technically, these are not C++ functions. I use to dabble in some Java every now and then, but then I started writing stand-alone applications and so I moved over to C/C++.

If you feel like looking through some fairly simplistic MFC stuff, check out RoboCon. It’s a VERY minimal UI, but it will let you see how easy MFC truly is. If you want a bigger project, look at RoboEmu. Then compare that to RoboGUI, which is written without the help of MFC. You’ll notice that about 3/4 of RoboGUI is UI code, whereas less than 1/10 of RobEmu is.

As for books, I’ve liked everything from Deitel&Deitel that I have. C++: How To Program, 2nd ed taught me EVERYTHING I know about C++, and Java: How To Program tauge me EVERYTHING I know about Java. If you want a good book on the Windows API, check out Charles Petzold’s Programming Windows. It doesn’t cover MFC, but it has just about everything else you could ever want to know. Besides that, the MSDN library is a truly amazing resource. I learned MFC purely from reading throught the library while writing RoboEmu.

As another note, this year (I’m a senior now) is the first year I have ever taken a programming class, mainly because my high school doesn’t offer any. The key is to get a book and start reading. After that, try some of the example problems in the book, and then some of the excercises they provide at the end of each chapter.


(As for a special diet, Coke normally does the trick as does getting an average of 4 hours of sleep per night)