簡體   English   中英

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

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

通過多個線程發送消息以進行卷曲,並且有時我收到以下錯誤之一。

curl_easy_perform():失敗的ssl連接錯誤。 sschannel:下一個initializesecuritycontext失敗:SEC_E_MESSAGE_ALTERED

curl_easy_perform():失敗的ssl連接錯誤。 sschannel:下一個initializesecuritycontext失敗: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;
}

“發送消息以通過多個線程卷曲...”-給定描述的症狀,最合乎邏輯的做法是假設與多線程相關的問題

  • libcurl本身是線程安全的,但不是共享的數據和使用的句柄。 您可能需要查詢以下頁面: https : //curl.haxx.se/libcurl/c/threadsafe.html並確保您的線程不會互相踩到腳趾

  • 一種(可能)簡單的方法來確認上述假設-嘗試以單線程模式運行程序(如果可以),看看問題是否再次發生。 如果這樣做的話,那肯定不是線程。

  • 另一種驗證方式(如果不是上述選項),在curl操作上放置線程互斥鎖(甚至在開始設置curl選項之前)-看看這是否有助於避免這些錯誤

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM