简体   繁体   English

curl_easy_perform():: SSL_connect_error-如何解决?

[英]curl_easy_perform(): : SSL_connect_error - How to resolve it?

Sending messages to curl via multiple threads, and once a while I get one of the following errors. 通过多个线程发送消息以进行卷曲,并且有时我收到以下错误之一。

curl_easy_perform(): failed ssl connect error. curl_easy_perform():失败的ssl连接错误。 sschannel: next initializesecuritycontext failed: SEC_E_MESSAGE_ALTERED sschannel:下一个initializesecuritycontext失败:SEC_E_MESSAGE_ALTERED

curl_easy_perform(): failed ssl connect error. curl_easy_perform():失败的ssl连接错误。 sschannel: next initializesecuritycontext failed: SEC_E_BUFFER_SMALL sschannel:下一个initializesecuritycontext失败:SEC_E_BUFFER_SMALL

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. 但是,为什么会发生此错误(在接下来的40秒内执行相同的请求),可以采取什么措施来避免这种情况。

Source code is written in C++. 源代码是用C ++编写的。 LibCurl was built using Microsoft visual studio 2010. Following is the code that invokes the curl library. LibCurl是使用Microsoft Visual Studio 2010构建的。以下是调用curl库的代码。

CURL *curl = curl_easy_init();
if (curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "connection-page");
    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, &resPonseInfo);
    curl_easy_setopt(curl, CURLOPT_HEADERDATA, &headerResponse);
    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_ANY);
    res = curl_easy_perform(curl);
    if ((res != CURLE_OK))
    {
        fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
        std::cout << "Request === " << std::endl;
        std::cout << requestToPost << std::endl;
        std::cout << "Error === " << std::endl;
        std::cout << curlErrorbuffer << std::endl;
        std::cout << "Header == " << std::endl << headerResponse.str() << std::endl;
        std::cout << "Response == " << std::endl << resPonseInfo.str() << std::endl;
    }
    else // if(res == CURLE_OK)
    {
        std::cout << "Response from the http post was successful " << std::endl;
        responseInfo = resPonseInfo.str();
    }
    curl_easy_cleanup(curl);
    curl = NULL;
}

"Sending messages to curl via multiple threads..." - given described symptoms most logical would be to assume a multi-threading related issue “发送消息以通过多个线程卷曲...”-给定描述的症状,最合乎逻辑的做法是假设与多线程相关的问题

  • libcurl itself a thread safe, but not the shared data and handles used. libcurl本身是线程安全的,但不是共享的数据和使用的句柄。 You might want to consult this page: https://curl.haxx.se/libcurl/c/threadsafe.html and ensure your threads are not stepping each other toes 您可能需要查询以下页面: https : //curl.haxx.se/libcurl/c/threadsafe.html并确保您的线程不会互相踩到脚趾

  • one (possibly) easy way to confirm above hypothesis - try running your program in a single thread mode (if you can) and see if the issue reoccurs. 一种(可能)简单的方法来确认上述假设-尝试以单线程模式运行程序(如果可以),看看问题是否再次发生。 If it does then it's definitely not threading. 如果这样做的话,那肯定不是线程。

  • another way to verify (if above is not an option) put a thread mutex on your curl operation (even before you start setting up curl options) - see if that help avoiding those errors 另一种验证方式(如果不是上述选项),在curl操作上放置线程互斥锁(甚至在开始设置curl选项之前)-看看这是否有助于避免这些错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM