CURL请求失败重试方法
CURL Request Failure retry method
我使用CURL库进行POST、GET、下载和上传数据。出于某种原因,如果请求失败,我们计划再次重试该请求。我们计划重试5次,即使失败了,我们也会停止并向用户显示失败消息。为此,我们以10秒的延迟在循环中运行。
我的问题。
1) 是我的做法是正确的。
2) 什么是最佳实践。
更新:
int _tmain(int argc, _TCHAR* argv[])
{
CURL *curl;
CURLcode res;
int nRetryCount = 0;
do
{
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/");
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK == res)
{
break;
}
nRetryCount++;
if (nRetryCount < 5)
{
//wait for 10 sec.
Sleep(10000);
}
}
} while (nRetryCount < 5);
curl_global_cleanup();
return 0;
}
您最好检查http状态代码。
curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &http_status);
if (http_status == ...) {
break;
}
相关文章:
- 离开方法时重置变量值
- 在 c++ 中重置大型对象实例的最佳方法是什么
- OpenGL 顶点缓冲区类重定义和模板方法错误
- C libcurl错误重试
- 我试着了解方法覆盖是如何工作的,不知道为什么输出 2
- 如何轻松地将 Base 方法重定向到相同的派生类方法
- 为什么当循环再次运行时,此输出"请重试"?
- 网络tcp套接字应用程序重试方法
- 正在重试包含同一异常的exception_ptr的多个实例
- 未收到确认时如何执行数据包重试
- 出现异常后重试本地静态变量初始化
- 虚拟方法重定向错误
- LIBMEMCACHED :服务器已失败并禁用,直到定时重试
- 使用擦除方法重置循环内的迭代器
- Android 冻结在 OpenGL|ES 中(CPU 可能被固定,重试)
- 从catch块中的函数重试
- 在Poco 1.5.x中使用锁定的SQLite数据库重试
- CURL请求失败重试方法
- "相机正在使用中。关闭使用它的所有应用程序,然后重试。在黑莓 Z10 中调用黑莓 10 级联中的相机时
- 正在重试异常