【问题标题】:cURL CONNECTTIMEOUT alertcURL CONNECTTIMEOUT 警报
【发布时间】:2010-11-09 14:23:46
【问题描述】:

我正在做这个项目,其中一小部分是连接到服务器并做一些事情,如果它在一段时间内无法连接到服务器,则给出错误消息.. 我知道 curl 代码看起来像这样 curl_easy_setopt(c,CURLOPT_CONNECTTIMEOUT,1L); 而且它还有一个 MilliSecond 选项。我想要的是让程序在 curl 无法在给定时间内(在本例中为 1 秒)连接到服务器时提醒我。

【问题讨论】:

    标签: c++ curl


    【解决方案1】:

    你试过了吗?

    char* pErrorBuffer = NULL;
    pErrorBuffer = (char*)malloc( 512 );
    memset( pErrorBuffer, 0, 512 );
    curl_easy_setopt( curlHandle, CURLOPT_ERRORBUFFER, pErrorBuffer );
    curl_easy_setopt( curlHandle, CURLOPT_CONNECTTIMEOUT, 1 ); // 1 s connect timeout
    if( CURLE_OK != curl_easy_perform( curlHandle ) )
    {
        // pErrorBuffer contains error string returned by cURL
        pErrorBuffer[511] = '\0';
        printf( "cURL returned: %s", pErrorBuffer );
    }
    // Free when you're done.
    free( pErrorBuffer );
    

    【讨论】:

      猜你喜欢
      • 2011-07-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2023-03-11
      • 2016-05-09
      • 2016-08-14
      • 2014-12-02
      • 2019-04-15
      相关资源
      最近更新 更多