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

问题描述 投票:-1回答:1

通过多个线程将消息发送到curl,并且偶尔会出现以下错误之一。

curl_easy_perform():失败的ssl连接错误。 sschannel:next initializesecuritycontext failed:SEC_E_MESSAGE_ALTERED

curl_easy_perform():失败的ssl连接错误。 sschannel:next initializesecuritycontext failed:SEC_E_BUFFER_SMALL

截至目前,我正在通过重新发送请求来解决这个问题。但是为什么会发生这种错误(在接下来的40秒内发出相同的请求)以及可以采取哪些措施来避免这种情况。

源代码是用C ++编写的。 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;
}
c++ multithreading curl libcurl
1个回答
2
投票

“通过多个线程发送消息卷曲......” - 给出描述的症状最合乎逻辑的是假设多线程相关问题

  • libcurl本身是一个线程安全的,但不是使用的共享数据和句柄。您可能需要查阅此页面:https://curl.haxx.se/libcurl/c/threadsafe.html并确保您的线程没有互相踩踏板
  • 一种(可能)简单的方法来确认上述假设 - 尝试在单线程模式下运行程序(如果可以)并查看问题是否再次发生。如果它确实那么它绝对不是线程。
  • 验证(如果上面不是一个选项)的另一种方法是在你的curl操作上放置一个线程互斥(甚至在你开始设置curl选项之前) - 看看是否有助于避免这些错误
© www.soinside.com 2019 - 2024. All rights reserved.