0

Curl works most of time, when it failed it returns OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to bootstrap.cn:443

Here is my code:

curl = curl_easy_init(); 
if(curl!=NULL){
    curl_easy_setopt(curl,CURLOPT_URL,curl_url);
    curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,&save_response_callback);
    curl_easy_setopt(curl,CURLOPT_WRITEDATA,&response);

    curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);
    curl_easy_setopt(curl,CURLOPT_CAINFO,caPath);
    curl_easy_setopt(curl,CURLOPT_SSL_VERIFYHOST,0);
    curl_easy_setopt(curl,CURLOPT_VERBOSE,1L);
    curl_easy_setopt(curl,CURLOPT_TIMEOUT,60);

    /*  below is the CA on the client side*/
    curl_easy_setopt(curl,CURLOPT_SSLCERT,certPath);
    curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");
    curl_easy_setopt(curl,CURLOPT_SSLKEY,keyPath);
    curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,"PEM");
    curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, *sslctx_function);

    /*  upload message through post method*/
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, upload_json);
    memset(head,0,sizeof(head));
    sprintf(head,"deviceid: mac:%s",hc_config->hc_config_data.mac);
    headers=curl_slist_append(headers, head);
    headers=curl_slist_append(headers, "Content-Type:application/json");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    res = curl_easy_perform(curl);
    res_code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,&http_status);
    printf("The res=%d, res_code=%d,connect response code=%03ld\n", res,res_code,http_status);

    if(res != CURLE_OK)
        printf("curl_wasy_perform error = %s",curl_easy_strerror(res));
    printf("Response:\n%s\n",response.data);
    curl_easy_cleanup(curl);

(To avoid breaking company rules, I used a false domain name)

I noticed that someone asked a similar question, but his code was written in PHP, mine in C. I don't know how to apply his solution.

Here is the link: Curl works 90% of the time, 10% it fails with OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.site.com:443

Thanks in advance !!!

0 Answers0