8

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!

Sophia
  • 155
  • 2
  • 13
  • Have you tried this: [How do you make a HTTP request with C++?](http://stackoverflow.com/questions/1011339/how-do-you-make-a-http-request-with-c)? – metacubed May 16 '14 at 04:31
  • 1
    Yes I have looked at that page already. curlpp however is a pain to deal with and I get several errors with missing header files and whatnot every time I try. I have not tried the other APIs mainly because I am exhausted from dealing with configuration (and my success rate with them are usually quite minimal.) – Sophia May 16 '14 at 04:39
  • Why don't use posix socket (winsock) to open a tcp connection to port 80, and then send something like `GET /?ip="100.100.100.100 HTTP/1.0\r\n\r\n`? Opening a socket in C is literally 10 lines of code. – tofi9 May 16 '14 at 04:52
  • 1
    What about this? http://stackoverflow.com/questions/22077802/simple-c-example-of-doing-an-http-post-and-consuming-the-response/22135885#22135885 It isn't exactly the same because he wanted to send it to a different place with different query string but it should be close. – Jerry Jeremiah May 16 '14 at 04:54
  • Can't believe I didn't find that question/answer Jerry linked. As for sockets, my superior said I didn't need to get to the "socket" level so I didn't bother, but I guess I'm wrong. Am looking at both right now. – Sophia May 16 '14 at 05:04
  • Did you see [this][1] post already? [1]: http://stackoverflow.com/questions/1107862/http-client-example-on-win32 – RC Brand May 16 '14 at 06:31
  • Take a look at C++ REST SDK (Casablanca) https://casablanca.codeplex.com it allows to send async HTTP requests and has a ports for several platforms – vard May 16 '14 at 06:31
  • You can of course build libcurl completely staticly into your own app, not requiring any separate DLL. If you wanted to. – Daniel Stenberg May 17 '14 at 08:14

1 Answers1

2

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.

Sophia
  • 155
  • 2
  • 13