Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple HTTP request with C++

Before you flag this for redundancy, do know that I have tried a lot of the methods posted around the web (stack overflow included) already and they each couldn't satisfy my needs. Also do note I am quite new to the programming world so excuse me for my misuse of technical terms.

Right now I am writing a C++ program that computes some data from the user's computer (IP address for example), then I send the IP address to a server that's already set up. I do this through an URL. So for example, if the server is at http://stack1234abcdz.com, and the user's IP address is 100.100.100.100 , then I would request

http://stack1234abcdz.com/?ip="100.100.100.100

I have tried libcurl and it works to some extent, but after compiling, I require 5 .dll in the same directory as the .exe in order to run it, which I cannot have due to some portability of my problem.

I have also tried some other traditional socket methods, but they require loads of libraries and SDKs, which are hard to configure and they often overwhelm a newbie like me. What I need to do is very simple (I don't even need the server to send anything back except for maybe success or failure codes), therefore I don't think I should be needing so much to do so little.

I am using Visual Studio 2006 on Windows 7 (64 bit) machine, doing C++. I cannot use newer versions because most of the other code that was given to me is in VS2006 and they do not transfer/convert well to newer versions.

I guess what I'm asking now is what I should do next. Is there a way to make the executable with libcurl to NOT use 5 .dll? I saw somewhere that I have to do some static linking stuff, but they weren't being very specific.

Or are there simpler ways to solve my problem that I overlooked? WinInet? CAtlHttpClientT? Casablanca? I'd prefer not to install and configure complex libraries that I have yet to grasp my mind around, especially not for the size of my problem...

I would appreciate any help/opinion/feedback on this matter, thanks!

like image 380
Sophia Avatar asked May 16 '14 04:05

Sophia


People also ask

What is POST in C?

Increment operators are the operator of the C programming language used to increase the given variable's value by 1. The increment operator can increase the given value by 1 before assigning it to the variable.

What are the 3 main parts of an HTTP request?

HTTP Response broadly has 3 main components: Status Line. Headers. Body (Optional)


1 Answers

After lots of trials and errors I solved my own problem. I used OpenURL() function in the CInternetSession class. Did a simple open in around 25 lines of code. Ran into some problems while including afxinet.h, stdafx.h, httpClient.h. That order worked for me, but might be different for other programs.

like image 94
Sophia Avatar answered Oct 03 '22 13:10

Sophia