当前位置:   article > 正文

CURLOPT_TIMEOUT 超时问题 导致 curl_easy_perform返回28

CURLOPT_TIMEOUT 超时问题 导致 curl_easy_perform返回28

    今天在测试排查一个奇怪的问题,图片发送有时会发不出去,(50%的概率)一开始觉得是网络

的问题或者是对方服务器有问题,ping了一下,反应还是挺快的,而且其它设备对外网的反应还是

好的,进入设备查看打印,没发送出去的curl_easy_perform返回值28

  1. _pcResponse[0] = '\0';
  2. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_URL, _pcUrl);
  3. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_READFUNCTION, NULL);
  4. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_POST, 1);
  5. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_WRITEFUNCTION, OnCurlRecvData);
  6. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_WRITEDATA, (void *)_pcResponse);
  7. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_POSTFIELDS, _pcPostBuf);
  8. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_POSTFIELDSIZE, (long)strlen(_pcPostBuf));
  9. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_TIMEOUT, 3L);
  10. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_HEADER, 1);
  11. http_headers = curl_slist_append(http_headers, "Accept: application/json,application/VIID+json");
  12. http_headers = curl_slist_append(http_headers, "Content-Type: application/VIID+JSON;charset=UTF-8");
  13. http_headers = curl_slist_append(http_headers, "Connection: keepalive");
  14. http_headers = curl_slist_append(http_headers, cUserIdentify);
  15. http_headers = curl_slist_append(http_headers, _AuthBuf);
  16. http_headers = curl_slist_append(http_headers, "User-Agent: libghttp/1.0");
  17. (void)curl_easy_setopt(pstCurlEasy, CURLOPT_HTTPHEADER, http_headers);
  18. iRet = curl_easy_perform(pstCurlEasy);
  19. if(iRet != CURLE_OK)
  20. {
  21. Gat1400Log_Error("iRet = %d\n", iRet);
  22. goto end;
  23. }

于是进入搜索了一下为什么返回28,查了一下是因为超时,于是根据网络上的添加相应设置

 curl_easy_setopt(pEasy, CURLOPT_VERBOSE, 1);

再进行运行,出现了下面的

一看就知道了,和服务器交互的时间很显示大于了设置的时间3L,然后我尝试把超时时间加大

(void)curl_easy_setopt(pstCurlEasy, CURLOPT_TIMEOUT, 30L);

然后再运行,放入测试的环境(在我自己的电脑上3秒就够了,不会出现测试的那种超时现象。。。。)

果然就好使了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/968647
推荐阅读
相关标签
  

闽ICP备14008679号