title: curl_easy_perform(): : SSL_connect_error - How to resolve it?
body: <p>Sending messages to curl via multiple threads, and once a while I get one of the following errors.</p>
  <blockquote>
  <p>curl_easy_perform(): failed ssl connect error. sschannel: next
  initializesecuritycontext failed: SEC_E_MESSAGE_ALTERED</p>
  <p>curl_easy_perform(): failed ssl connect error. sschannel: next
  initializesecuritycontext failed: SEC_E_BUFFER_SMALL</p>
  </blockquote>
  <p>As of now, I'm resolving this by re-sending the request. But why does this error happen ( Same request in the next 40 seconds works) and what can be done to avoid this.</p>
  <p>Source code is written in C++. LibCurl was built using Microsoft visual studio 2010.
  Following is the code that invokes the curl library.</p>
  <pre><code>CURL *curl = curl_easy_init();
  if (curl) {
      curl_easy_setopt(curl, CURLOPT_URL, &quot;connection-page&quot;);
      curl_easy_setopt(curl, CURLOPT_POST, 1);
      curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestToPost.c_str());
      curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(requestToPost.c_str()));
      curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
      curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerInfo);
      curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, header_data);
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
      curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curlErrorbuffer);
      std::stringstream resPonseInfo;
      std::stringstream headerResponse;
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &amp;resPonseInfo);
      curl_easy_setopt(curl, CURLOPT_HEADERDATA, &amp;headerResponse);
      curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
      res = curl_easy_perform(curl);
      if ((res != CURLE_OK))
      {
          fprintf(stderr, &quot;curl_easy_perform() failed: %s\n&quot;, curl_easy_strerror(res));
          std::cout &lt;&lt; &quot;Request === &quot; &lt;&lt; std::endl;
          std::cout &lt;&lt; requestToPost &lt;&lt; std::endl;
          std::cout &lt;&lt; &quot;Error === &quot; &lt;&lt; std::endl;
          std::cout &lt;&lt; curlErrorbuffer &lt;&lt; std::endl;
          std::cout &lt;&lt; &quot;Header == &quot; &lt;&lt; std::endl &lt;&lt; headerResponse.str() &lt;&lt; std::endl;
          std::cout &lt;&lt; &quot;Response == &quot; &lt;&lt; std::endl &lt;&lt; resPonseInfo.str() &lt;&lt; std::endl;
      }
      else // if(res == CURLE_OK)
      {
          std::cout &lt;&lt; &quot;Response from the http post was successful &quot; &lt;&lt; std::endl;
          responseInfo = resPonseInfo.str();
      }
      curl_easy_cleanup(curl);
      curl = NULL;
  }
  </code></pre>