Making An API Call Using cURL in C++

  • Thread starter Thread starter EliC
  • Start date Start date
Joined
8/28/17
Messages
123
Points
138
I am trying to use cURL to make an API call so I can start getting real time stock data, but I am running into difficulties getting it to function in VS 2017. I have attempted an install using vcpckg using the following steps:

1. Clone vpckg using gitbash into C:\Program Files (see Step1.png)
2. In a CMD prompt navigate to C:\Program Files\vcpkg
3. Run in the command prompt: .\bootstrap-vcpkg.bat
4. Run in the command prompt: vcpkg integrate install
5. Run in the command prompt: vcpkg install sdl2 curl


According to vcpkg documentation I should be able to now simply "#include <curl.h>", but it can't find the folder. If I try including the "include" directory from curl and "#include <curl/curl.h> I can build my project. But if I try and set the "curl_global_init(
CURL_GLOBAL_DEFAULT)" as in this example I get linker errors (see LinkerError.png).

Any suggestions on how to get this up and running? I think if I can get API access, I will be much closer to being able to build a real trading system.
 

Attachments

  • Step1.webp
    Step1.webp
    58 KB · Views: 84
  • LinkerError.webp
    LinkerError.webp
    94.7 KB · Views: 83
I am trying to use cURL to make an API call so I can start getting real time stock data, but I am running into difficulties getting it to function in VS 2017. I have attempted an install using vcpckg using the following steps:

1. Clone vpckg using gitbash into C:\Program Files (see Step1.png)
2. In a CMD prompt navigate to C:\Program Files\vcpkg
3. Run in the command prompt: .\bootstrap-vcpkg.bat
4. Run in the command prompt: vcpkg integrate install
5. Run in the command prompt: vcpkg install sdl2 curl


According to vcpkg documentation I should be able to now simply "#include <curl.h>", but it can't find the folder. If I try including the "include" directory from curl and "#include <curl/curl.h> I can build my project. But if I try and set the "curl_global_init(
CURL_GLOBAL_DEFAULT)" as in this example I get linker errors (see LinkerError.png).

Any suggestions on how to get this up and running? I think if I can get API access, I will be much closer to being able to build a real trading system.
I see a similar issue was answered here, does this help?: Visual Studio 2015 curl will not statically link
 
@Andy Nguyen I checked out the thread and it seems like they have some options. I'll give them a try to see if they work. Otherwise I might try a more brute force solution (downloading to CSV or maybe calling Python from within my application). I'll update.

@APalley, I did give that a try and ended up with the same error. I did create a more detailed post about this question on stackoverflow here: Getting cURL to work with Visual Studios 2017. Hopefully someone thinks of something.
 
Good news everyone!

I got it working. Check the stackoverflow post I made here: link.

The next challenge was then to be able to get the response in a readable format, but following the getinmemory example from Curl's official documentation I was able to produce a string. I have attached a file HTTPRequest.h which contains the implementation. If you '#include HTTPRequest.h' you can call the function returnResponseAsString(string requestURL) which will return the response as a string. The function uses mostly C style syntax (malloc and realloc, though it also accepts a string as the parameter), but it works. Also note that I included the line:

curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);

This means that your request will not validate the certificate of the website and makes your request less secure. I did this because I couldn't figure out how to get the certificates to work.
 

Attachments

Last edited:
Back
Top Bottom