【问题标题】:Android and libCurl httpsAndroid 和 libCurl https
【发布时间】:2015-11-29 08:26:48
【问题描述】:

晚上好,

我需要在我们的一个 Android 项目中实现 libCurl。我使用 JNI 调用带有 libCurl 代码的 c++ 类。一切都很完美,但看在上帝的份上,我无法使用 https url 让它工作。 我总是收到 CURLE_UNSUPPORTED_PROTOCOL 错误。

我正在使用 this prebuild curl library 使用 SSL

我的 c++ 代码如下所示:

curl_easy_setopt(curl, CURLOPT_URL, "https://www.es....");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *)&cbProgress);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
curl_easy_setopt(curl, CURLOPT_SSLVERSION, 3);

status = curl_easy_perform(curl);

我在 iOS 上使用了相同的代码,并且它适用于 https。 同样,使用 http url 效果很好。

非常感谢任何帮助!

【问题讨论】:

    标签: android android-ndk libcurl


    【解决方案1】:

    来自libcurl errors manpage

       CURLE_UNSUPPORTED_PROTOCOL (1)
              The URL you passed to libcurl used a protocol that this  libcurl
              does  not  support.  The  support might be a compile-time option
              that you didn't use, it can be a misspelled protocol  string  or
              just a protocol libcurl has no code for.
    

    compile-time option 是其中的重要内容。所以,用curl_version_info()(manpage here)测试你正在使用的库,看看它是否包含SSL 支持。图书馆文档可能会说它支持SSL,但请确认。如果它不包含SSL 支持,则没有https

    【讨论】:

    • 谢谢萨姆文。我检查了 SSL 版本,它返回 (null)。当!您还有其他资源可以下载支持 SSL 的预编译 libcurl 库吗?
    • 为什么不自己构建呢?
    【解决方案2】:

    你需要用“--with-ssl”编译libcurl.so

    这真的很痛苦。参考“http://ieroot.com/2015/03/29/1728.html”,对你有帮助。

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 1970-01-01
      • 2019-12-16
      • 2012-04-29
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 2015-08-11
      相关资源
      最近更新 更多