Curl simple https request returns nothing c ++

I am using Visual Studio C ++ 2010 and it works fine with cURL, but the problem is that https requests return nothing. instead of displaying 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, is just an https request for Google, but it doesn't return anything just because it starts with https. and if I take the "s" https it works fine: "http://www.google.com.br" shows the result normally. what am I missing here? I am using an example from cURL. I tried with other websites and it happened.: / Like https://www.facebook.com

By the way, if you guys know how I can store the content of a webpage in a string, I'd be glad to know.

Thanks in advance.:)

+3


source to share


1 answer


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 created the library a long time ago, but I'm pretty sure I enabled SSL support before compiling the sources. Make sure you have OpenSSL installed and (if you are on Linux) you have initialized the variable correctly PKG_CONFIG_PATH

. These are the two parameters that you specify when executing your 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

      



Hope this helps.

If you are using Windows, this post might be helpful for you too:

Building libcurl with SSL support on Windows

+4


source







All Articles