3

I'm using Visual Studio C++ 2010 and it's working just fine with cURL but the problem is that https requests returns nothing. instead of showing the output:

#include "StdAfx.h"
#include <stdio.h>
#include <curl/curl.h>
#include <conio.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.com");
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  _getch();
  return 0;
}

This code for example, it's just a https request to Google, but it returns nothing just because it starts with https. and if I take away the "s" of https, it works just fine: "http://www.google.com.br" shows the result normally. what am I missing here? I'm using the example from the cURL. I tried with other websites and same thing happened. :/ like https://www.facebook.com

Btw also if you guys know how do I store the webpage content in a string, I would be glad to know.

Thanks in advance. :)

Grego
  • 2,220
  • 9
  • 43
  • 64
  • Is setting those ssl verify flags to zero really what you want? A little poking around seems to imply that it will bypass some level of verification. My first attempt would be to try and see if those flags can be cleared like that on the command line curl with the https url. I'd guess it would fail in much the same way. – Michael Wilson Mar 19 '12 at 19:55
  • Michael I'm not really sure. what I want is get a https correctly without any SSL security cause I want it to be fast to retrieve the data. but right now I get nothing :/ I want the way to get the fastest way even tho if it jeopardize the security of the data. – Grego Mar 19 '12 at 19:57
  • Did you build from source? If so, did you explicitly enable SSL support? If not, did the package you download have SSL support enabled (or, where did you download it from)? – ildjarn Mar 19 '12 at 20:01
  • I used this tutorial over here: curl.haxx.se/libcurl/c/Using-libcurl-with-SSH-support-in-Visual-Studio-2008.pdf I downloaded even the same versions of the things needed just to not conflict anything and on the same environment which was the Visual Studio C++ 2008, it works fine with everything else except with SSL. and it doesn't even show an error, just blank, like it didn't even tried to make the request and proceed the code. – Grego Mar 19 '12 at 20:15
  • I think this is a duplicate post with this one: [other post](http://stackoverflow.com/q/8912772/1265099) – Joost Sannen Mar 19 '12 at 20:20
  • wait wait... "what I want is [to] get a https correctly without any SSL security"... that's what the "s" in "https" is. "S"ecure Socket Layer. It sounds to me like you don't want SSL at all, which would mean just use straight http and you could forget the https, the SSL, those two flag parameters. – Michael Wilson Mar 19 '12 at 20:49

1 Answers1

6

This simple example works for me:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
    /* First set the URL that is about to receive our POST. This URL can
       just as well be a https:// URL if that is what should receive the
       data. */
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.google.co.uk");

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

I got the source code and built the library long time ago but I'm sure I enabled the SSL support before compiling the sources. Make sure you have OpenSSL installed and (in case you're working under Linux) you have the PKG_CONFIG_PATH variable initialized properly. These are two options you specify when executing the configure script.

  --with-ssl=PATH         Where to look for OpenSSL, PATH points to the SSL
                          installation (default: /usr/local/ssl); when
                          possible, set the PKG_CONFIG_PATH environment
                          variable instead of using this option

  --without-ssl           disable OpenSSL

I hope it helps.

If you're using Windows, this post can be also useful for you:

Building libcurl with SSL support on Windows

Community
  • 1
  • 1
user1192525
  • 657
  • 4
  • 20
  • Hey fella, I'm working on Windows 7 on Visual Studio C++ 2008 to be more specific, I have OpenSSL installed but I built it by the tutorial that has in the Curl Page for Visual Studio 2008, I had to download and install openssl to do it, but this application I'm doing I intend to distribute, will I have to ask everyone to install OpenSSL? but first, I would like to know where I tell the application to point to OpenSSL, I built it with support but I don't seem to get it working, if you have something to share I'll be glad. thanks. :) – Grego Mar 19 '12 at 21:05
  • oh yea is there a way to ignore the SSL and make the https even without the secure thing just to retrieve the html ? cause I don't care about the security, I'm only thinking about receiving the data from the server – Grego Mar 19 '12 at 21:20
  • Thank you. This just ended my hell on day 2. – Florin Mircea Dec 17 '13 at 16:01