gpt4 book ai didi

c++ - cURL CONNECTTIMEOUT 警报

转载 作者:太空狗 更新时间:2023-10-29 22:52:32 24 4
gpt4 key购买 nike

我正在做这个项目,其中一小部分是连接到服务器并做一些事情,如果它在一段时间内无法连接到服务器,则给出错误信息..我知道 curl 代码看起来像这样curl_easy_setopt(c,CURLOPT_CONNECTTIMEOUT,1L);并且它还有一个 MilliSecond 选项。我想要的是如果 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 );

关于c++ - cURL CONNECTTIMEOUT 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4134691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com