C++ and cUrl : how to get SSL error codes

前端 未结 1 1299
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 08:45

I am establishing a connection to a secured server over SSL. Everything works fine, my CAcertificate is well used through

retCode=curl_easy_setopt(handleCurl,          


        
相关标签:
1条回答
  • 2021-01-24 08:46

    Add to your connection setup code:

    // Make sure this is NOT a stack variable! The buffer
    // must be available through whole live of the connection
    char buffer[CURL_ERROR_SIZE+1] = {};
    
    retCode=curl_easy_setopt(handleCurl, CURLOPT_ERRORBUFFER, buffer);
    

    then when your connection has ended, check what's in the buffer - you should be able to see some hints regarding SSL state, too. It will be empty if no error occurred.

    If you want actual code, numeric CURLcode is always returned by curl_easy_perform for easy handles.

    If you use multi handles, use curl_multi_info_read instead. Here is example:

    int u = 0;
    if (CURLM_OK == curl_multi_perform(multi_, &u))
    {
      int q = 0;
      CURLMsg *msg = NULL;
      while ((msg = curl_multi_info_read(multi_, &q)) != NULL)
      {
        if (msg->msg == CURLMSG_DONE)
        {
          CURL* easy = msg->easy_handle;
          CURLcode code = msg->data.result;
          // . . .
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题