Hi guys,

I need to parse JSON data from an HTTPS protocol so I downloaded and integrated libcurl into my VS2010.
Everything works fine and sample codes work fine when I use "http" protocol.
However, a CURL error keeps coming out when I try to read from "https" protocol....

The error msg is "Error from cURL: Unsupported protocol"

My code is below. This code is from official web site (http://curl.haxx.se/libcurl/c/https.html) What am I missing?? Please help!

    CURL *curl;

    curl = curl_easy_init();
    if(!curl)
    {
        cout << "Unable to initialize cURL interface" << std::endl;
        return;
    }

    string curl_url = "https://www.cia.gov/";
    curl_easy_setopt(curl, CURLOPT_URL, curl_url.c_str());
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");

    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);


    const CURLcode rc = curl_easy_perform(curl);

    if( rc != CURLE_OK ) {
        cout << "Error from cURL: " << curl_easy_strerror(rc) << std::endl;
        return;
    }
    curl_easy_cleanup(curl);

Just ran you code and it worked for me:

#include <iostream>
#include <string>
#include <cstdio>
#include <curl/curl.h>
int main(void) {
    CURL *curl;

    curl = curl_easy_init();
    if(!curl) {
        std::cout << "Unable to initialize cURL interface" << std::endl;
        return -1;
    }

    std::string curl_url = "https://www.cia.gov/";
    curl_easy_setopt(curl, CURLOPT_URL, curl_url.c_str());
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");

    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);

    const CURLcode rc = curl_easy_perform(curl);

    if( rc != CURLE_OK ) {
        std::cout << "Error from cURL: " << curl_easy_strerror(rc) << std::endl;
    }
    curl_easy_cleanup(curl);
    return 0;
}

Output:

etc...

<title>Welcome to the CIA Web Site &mdash; Central Intelligence Agency</title>

<meta content="Central Intelligence Agency  " name="description" />

<!-- Internet Explorer CSS Fixes -->
<!--[if IE]>
    <style type="text/css" media="all">@import url(/css/IEFixes.css);</style>
<![endif]-->
<!-- Internet Explorer CSS Fixes -->
<!--[if IE]>

<![endif]-->


<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/images/touch_icon.png" />

etc...

hello guyz! i've seen this 1st time :/ wot sort of prgramming is it?? something relevant to Socketing?? or wot??

It worked?? Wow that is super odd... I guess some settings on my computer are different... hm....

Did you run on Visual Studio 2010 c++ project?

Edited 4 Years Ago by 9tontruck

However, a CURL error keeps coming out when I try to read from "https" protocol....
The error msg is "Error from cURL: Unsupported protocol"

You've probably downloaded a version without SSL support (you need SSL for the https protocol).

Edited 4 Years Ago by mitrmkar: edit

Here's a list of job done by me to integrate libcurl.

  1. Download curl-7.25.0.zip which was released on the 22nd of March from http://curl.haxx.se/download.html.
  2. Build libcurl with Visual Studio2010.
  3. C++ additional include:
    ...\libcurl-7.25.0\include;
  4. Linker Input:
    ...\libcurl-7.25.0\lib\DLL-Release\libcurl_imp.lib
    ...\libcurl-7.25.0\lib\LIB-Release\libcurl.lib
  5. Write the code above and build as release.
  6. Copy libcurl.dll tbb_debug.dll to the release folder.

Did I miss anything here? I believe curl-7.25.0.zip does support SSL as well.

Edited 4 Years Ago by 9tontruck

Use http://curl.haxx.se/libcurl/c/curl_version_info.html to get info on what you have. There a member to the struct called features which is a bit-mask.
host is an ascii string showing what host information that this libcurl was built for. As discovered by a configure script or set by the build environment.

features can have none, one or more bits set, and the currently defined bits are:

CURL_VERSION_IPV6

supports IPv6

CURL_VERSION_KERBEROS4

supports kerberos4 (when using FTP)

CURL_VERSION_SSL

supports SSL (HTTPS/FTPS) (Added in 7.10)

etc...

I checked curl_version_info_data and I figured out data->ssl_version is "null" which means the library I am currently using does not support SSL. What was wrong? Did I build the library in a wrong way? or the zipped library file in the very top of the download page does not basically contain SSL supports in it?

This article has been dead for over six months. Start a new discussion instead.