1. 程式人生 > >curl不能支持https問題

curl不能支持https問題

-i 目錄 xid 網上 verify share res compiler dap

默認情況下,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.18

Protocols: ftp gopher telnet dict ldap http file https ftps

Features: IDN IPv6 Largefile NTLM SSL libz

提示已經支持https了。

curl不能支持https問題