c++ - curl_easy_perform 返回 CURLE_WRITE_ERROR,但我不会写任何东西

标签 c++ iphone ios curl ios6

我写了这个简单的代码来检查网络连接或我们的 iOS 应用程序:

int CL_Network::checkConnectionInt1(){

  CURL *curl;
  CURLcode res;
  curl = curl_easy_init();

  if (curl) {

    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");

    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
    return res;

  }

  curl_easy_cleanup(curl);
  return -1;

}

我们的测试正常,启用 Wi-Fi 时返回 0,但 Apple 评论员在启用或禁用 Wi-Fi 时返回 23 (CURL_WRITE_ERROR)。

评论者告诉我们其他人的奇怪行为(考虑启用 Wi-Fi)

  • iOS 5.1 的 iPod touch 返回 0,与 iOS 6.3 的 iPhone5 相同的 Wi-Fi 返回 23
  • iPhone 5 with iOS 6.3 一步步调试返回0(不知道是只发生过一次还是一直发生)

你有什么建议吗?

最后一点,curl_easy_perform 的详细输出

  • About to connect() to www.google.com port 80 (#0)
  • Trying 173.194.35.20...
  • connected
  • Connected to www.google.com (173.194.35.20) port 80 (#0)

    GET / HTTP/1.1 Host: www.google.com Accept: /

< HTTP/1.1 302 找到 < 位置:http://www.google.it/ < Cache-Control: private < Content-Type: text/html;字符集=UTF-8 < 设置 Cookie: PREF=ID=08f8ea131f5d39dd:FF=0:TM=1367680782:LM=1367680782:S=at5IyKNTpeoFFnif; expires=Mon, 04-May-2015 15:19:42 GMT;路径=/;域名=.google.com < 设置 Cookie: NID=67=uPKHTXNtVuYy4QOwVHstK4NzMGZcDssYW.....; expires=2013 年 11 月 3 日星期日 15:19:42 GMT;路径=/;域名=.google.com; HttpOnly < P3P: CP="这不是 P3P 策略!看 http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 获取更多信息。” < 日期:2013 年 5 月 4 日星期六 15:19:42 GMT < 服务器:gws < 内容长度:218 < X-XSS-保护:1;模式= block < X 框架选项:SAMEORIGIN < 302 已移动

302 已移动

文档 已搬家here . * 与主机 www.google.com 的连接 #0 保持不变 *关闭连接#0 2013-05-04 17:19:42.183 testcurl[1468:c07] checkConnection 1: 0

最佳答案

你还需要写一个writecallback

size_t CurlWriteCallback(char* buf, size_t size, size_t nmemb, void* up)
{ 
    TRACE("CURL - Response received:\n%s", buf);
    TRACE("CURL - Response handled %d bytes:\n%s", size*nmemb);

    // tell curl how many bytes we handled
    return size*nmemb;
}

// ...



int CL_Network::checkConnectionInt1(){

  CURL *curl;
  CURLcode res;
  curl = curl_easy_init();

  if (curl) {

    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CurlWriteCallback);
    curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");

    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
    return res;

  }

  curl_easy_cleanup(curl);
  return -1;

}

关于c++ - curl_easy_perform 返回 CURLE_WRITE_ERROR,但我不会写任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16376104/

相关文章:

iphone - 新的 iOS 7 状态栏在 Xcode 5 中编译的应用程序中保留了 20px 的范围

iOS本地同时通知但不同日期有不同的提醒消息

ios - Swipeview 滞后于项目更改

iphone - 在 iphone 中单击按钮时如何查看 tableview Controller

c++ - 如何将c++实验库添加到mac编译器?

c++ - Win32 中是否有检测用户何时更改区域设置的消息或通知?

c++ - Qt找不到平台插件cocoa

iphone - 如何调整 UIModalPresentationFormSheet 的大小?

iphone - Phonegap iPhone : camera plugin : orientation issue

c++ - 用户输入验证无效