cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: curl_easy_perform error CURLE_UNSUPPORTED_PROTOCOL

From: Steve Holme <steve_holme_at_hotmail.com>
Date: Wed, 6 Aug 2014 22:10:54 +0100

On Fri, 18 Jul 2014, Nancy Ng wrote:

> I have been trying to use libcurl the library you have created
> and its all looking great.  However I have experience a problem
> of an error CURLE_UNSUPPORTED_PROTOCOL .   I am trying to
> pass https url , json to do a post action using the code below,
> however I kept getting CURLE_UNSUPPORTED_PROTOCOL
> after curl_easy_perform being called. Wonder if you could point
> me to the right direction.

HI Nancy,

My apologies for not replying sooner but I haven't been particularly active
with curl over the last month or so and am just starting to get back into
coding and catching up on emails.

Please note, I have added you on the cc of this email I have replied
directly to the libcurl distribution list as a) this is where all the other
libcurl hackers hang out and as such b) is a better place to obtain help and
support for libcurl.

Whilst I don't mind personal emails I am not the primary developer or
maintainer of the library so cannot take credit for its creation and may not
always be around to assist :( As such I would suggest signing up at:
http://cool.haxx.se/mailman/listinfo/curl-library

It seems to me, that you are trying to use a version of libcurl that hasn't
been compiled against an SSL backend, such as OpenSSL, Darwin on OS/X or
SSPI (SChannel) on Windows so any SSL based protocol (such as HTTPS, SMTPS,
FTPS, etc...) won't be available.

What target platform are you building for, what version of libcurl are you
compiling against and did you compile it yourself or download it from
somewhere?

Kind Regards

Steve

PS. So other readers can understand what you are trying to do, and
potentially provide suggestions, I have simply quoted your code snippet
below in raw form below.

RestClient::response RestClient::post(const std::string& url,
                                      const std::string& ctype,
                                      const std::string& data)
{
  /** create return struct */
  RestClient::response ret = {};
  /** build content-type header string */
  std::string ctype_header = "Content-Type: " + ctype;

  // use libcurl
  CURL *curl = NULL;
  CURLcode res = CURLE_OK;

  curl = curl_easy_init();
  if (curl)
  {
    /** set basic authentication if present*/
    if(RestClient::user_pass.length()>0){
      curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_easy_setopt(curl, CURLOPT_USERPWD,
RestClient::user_pass.c_str());
    }
       res=curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
       res=curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
    /** set user agent */
    res=curl_easy_setopt(curl, CURLOPT_USERAGENT, RestClient::user_agent);
    /** set query URL */
    res=curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
    /** Now specify we want to POST data */
    res=curl_easy_setopt(curl, CURLOPT_POST, 1L);
    /** set post fields */
    res=curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
    res=curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.size());
    /** set callback function */
    res=curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
RestClient::write_callback);
    /** set data object to pass to callback function */
    res=curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ret);
    /** set the header callback function */
    res=curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,
RestClient::header_callback);
    /** callback object for headers */
    res=curl_easy_setopt(curl, CURLOPT_HEADERDATA, &ret);

    /** set content-type header */
    curl_slist* header = NULL;
    header = curl_slist_append(header, ctype_header.c_str());
    res=curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
    /** perform the actual query */
    res = curl_easy_perform(curl);
    if (res != CURLE_OK)
    {
      ret.body = "Failed to query.";
      ret.code = -1;
      return ret;
    }

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-08-06