curl不能支援https問題

來源:互聯網
上載者:User

預設情況下,libcurl不支援https, 如果使用https連結,就會出現" Protocol https not supported or disabled in libcurl" 的錯誤提示。查看curl是否支援https可以使用命令:

curl -V。

curl有兩種方式使用https :

1. 設定為不驗證認證和HOST

code = curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L);

2. 設定一個SSL判別認證

http://curl.haxx.se/ca/cacert.pem

基於這兩種方法都不知道怎麼去使用,所以只好用最笨的方法,重裝curl:

1.下載curl-7.14.0.tar.gz壓縮包,網上很多

2.解壓:# tar -zxvf curl-7.14.0.tar.gz

# cd curl-7.14.0

# ./configure 這裡注意的是最後會顯示一段資訊提示是否支援https:

  curl version:    7.14.0  Host setup:      x86_64-unknown-linux-gnu  Install prefix:  /usr/local  Compiler:        gcc  SSL support:     no      (--with-ssl / --with-gnutls)  zlib support:    enabled  krb4 support:    no      (--with-krb4*)  GSSAPI support:  no      (--with-gssapi)  SPNEGO support:  no      (--with-spnego)  c-ares support:  no      (--enable-ares)  ipv6 support:    enabled  IDN support:     enabled  Build libcurl:   Shared=yes, Static=yes  Built-in manual: enabled  Verbose errors:  enabled (--disable-verbose)  SSPI support:    no      (--enable-sspi)  ca cert path:    no

這裡的SSL support提示的是不支援的,因為https協議是加密安全的基於http的協議,需要使用openssl的靜態庫,所以需要支援https就必須下載openssl,這裡不做贅述,方法可見:http://www.linuxidc.com/Linux/2011-01/31229.htm

# vi /etc/ld.so.conf,在這裡面將openssl產生的庫檔案所在目錄加入,使用命令ldconfig重新整理緩衝。

# ./configure --prefix=/usr/local/curl --with-ssl=/usr/local/ssl ,注意最後一段資訊

  curl version:    7.14.0  Host setup:      x86_64-unknown-linux-gnu  Install prefix:  /usr/local  Compiler:        gcc  SSL support:     enabled (OpenSSL)  zlib support:    enabled  krb4 support:    no      (--with-krb4*)  GSSAPI support:  no      (--with-gssapi)  SPNEGO support:  no      (--with-spnego)  c-ares support:  no      (--enable-ares)  ipv6 support:    enabled  IDN support:     enabled  Build libcurl:   Shared=yes, Static=yes  Built-in manual: enabled  Verbose errors:  enabled (--disable-verbose)  SSPI support:    no      (--enable-sspi)  ca cert path:    /usr/local/share/curl/curl-ca-bundle.crt

提示支援openssl已經支援了,然後再make, make install即可。

# curl -V

curl 7.14.0 (x86_64-unknown-linux-gnu) libcurl/7.14.0 OpenSSL/1.0.1e zlib/1.2.3 libidn/1.18Protocols: ftp gopher telnet dict ldap http file https ftps Features: IDN IPv6 Largefile NTLM SSL libz 

提示已經支援https了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.