I've been trying to learn more about CURL recently and finally managed to compile and install it properly as a static library for my test project. Eventually I'll move on to learning about posting forms and such.
I've successfully managed to connect and print out page content from http://www.google.se
.
When connecting to a secure http page https://www.google.se
I get an empty string as page content.
I'm using this to get information about the options.
I've tried the things from this answer, but it didn't work or I did it wrong.
I also tried turning off verifypeer and verifyhost (though I really want to practice safe solutions), but it didn't work either.
What do I need to do to make it work? Am I doing something wrong?
Here's the test code
#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp){
((string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(){
CURL *curl;
CURLcode res;
string readBuffer;
curl = curl_easy_init();
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.se");
//curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE);
//Doesn't seem to work
curl_easy_setopt(curl, CURLOPT_CAINFO, "path\\cacert.pem");
//Neither does this
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
cout<<readBuffer<<endl;
system("pause");
}
return 0;
}
Update
So I got the error message from curl saying Unsupported protocol
, which I'm guessing is what it says when SSL doesn't work. So I had to recompile it with SSL (which is odd, because I thought I did the first time) but...
I'm almost about to give up. Sigh. For some reason or other, now it gave me the error
NMAKE: fatal error U1077 nasmw
when making the SSL, even though I clearly gave it the right %PATH% to nasm. I followed the steps to the letter.
So I tried using the curl binaries of type libcurl, but I don't know how to link it properly in VC++ because the library files are unfamiliar to me.
I keep getting these linker errors when trying to compile the test project.
1>main.obj : error LNK2019: unresolved external symbol _curl_easy_cleanup referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _curl_easy_strerror referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _curl_easy_perform referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _curl_easy_setopt referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol _curl_easy_init referenced in function _main
So frustrated... I wish I understood why it has to be so complicated.
I just want to use the library already!
Update 2
Ok... I managed to compile the curl library with SSL and reporting CURL_VERSION_SSL
is enabled
curl_version_info_data * vinfo = curl_version_info(CURLVERSION_NOW);
if(vinfo->features & CURL_VERSION_SSL){
cout<<"CURL: SSL enabled"<<endl;
}else{
cout<<"CURL: SSL not enabled"<<endl;
}
//Prints out "CURL: SSL enabled"
but I'm still getting the same error message Unsupported protocol
. I don't know what I'm doing wrong.