配置windows下的curl来获取https页面内容

作者:lizongbo 发表于:14:05. 星期五, 十月 26th, 2007
版权声明:可以任意转载,转载时请务必以超链接形式标明文章和作者信息及本版权声明。

刚刚看到了javayou提到了可以在windows下使用的curl命令,

http://www.javayou.com/html/diary/showlog.vm?sid=2&log_id=13985

于是下载了支持ssl的curl来使用:
下载连接为: http://www.execve.net/curl/curl-7.17.0-win32-ssl.zip

解压到D:\Programs\-7.17.0
下载OpenSSL组件:

http://618119.com/OpenSSL/libeay32.dll

http://618119.com/OpenSSL/libssl32.dll

将libssl32.dll和libeay32.dll复制到D:\Programs\curl-7.17.0,

否则运行curl.exe会被提示:

—————————
curl.exe – 无法找到组件
—————————
没有找到 libeay32.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————

—————————
curl.exe – 无法找到组件
—————————
没有找到 ,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。
—————————
确定
—————————
(参考: http://618119.com/archives/2007/10/26/15.html)
如果需要连接的网站使用的证书不是操作系统已经信任的证书,则需要指定ca根证书文件.
并且服务器的证书CN必须与url里的host一致,否则无法下载.

测试命令示例如下:

curl https://www.google.com/

curl https://www.618119.com/

curl https://lizongbo.618119.com/ ca.crt

D:\Programs\curl-7.17.0>curl https://www.google.com/
<HTML><HEAD><meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A href=”http://www.google.com”>here</A>.
</BODY></HTML>

D:\Programs\curl-7.17.0>curl https://618119.com/
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
d
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a “bundle”
of Certificate Authority (CA) public keys (CA certs). The default
bundle is named curl-ca-bundle.crt; you can specify an alternate file
using the –cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you’d like to turn off curl’s verification of the certificate, use
the -k (or –insecure) option.

D:\Programs\curl-7.17.0>curl https://lizongbo.618119.com/ –cacert ca.crt
curl: (51) SSL: certificate subject name ’618119.com’ does not match target host name ‘lizongbo.618119.com’

Tags: , , ,

标签: , , ,


分享到 Google Buzz
点此分享到QQ空间
点此分享到腾讯微博

10 条评论 发表在“配置windows下的curl来获取https页面内容”上

  1. mclkyo 说道:

    D:\Programs\curl-7.17.0>curl https://618119.com/
    curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
    d

    像这样子的报的错误是什么原因呢?希望指点一二,谢谢

    Reply

    lizongbo reply on 十二月 13th, 2010:

    你可以找一台Linux的服务器,然后从上面复制一个文件来直接诶使用,通常路径是/usr/share/curl/curl-ca-bundle.crt,将这个文件复制到curl.exe所在的目录即可。
    比如我的是:D:\Programs\curl\bin,然后再运行curl命令即可:

    没有curl-ca-bundle.crt之前:
    D:\Programs\curl\bin>curl https://www.google.com
    curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify faile
    d
    More details here: http://curl.haxx.se/docs/sslcerts.html

    curl performs SSL certificate verification by default, using a “bundle”
    of Certificate Authority (CA) public keys (CA certs). The default
    bundle is named curl-ca-bundle.crt; you can specify an alternate file
    using the –cacert option.
    If this HTTPS server uses a certificate signed by a CA represented in
    the bundle, the certificate verification probably failed due to a
    problem with the certificate (it might be expired, or the name might
    not match the domain name in the URL).
    If you’d like to turn off curl’s verification of the certificate, use
    the -k (or –insecure) option.

    有了D:\Programs\curl\bin\curl-ca-bundle.crt之后:
    D:\Programs\curl\bin>curl https://www.google.com
    302 Moved
    The document has moved here

    文件已经发到你的邮箱,请查收。

  2. jqk 说道:

    发现这个blog程序对发的消息有改动.
    连续两个减号(英文字符)
    --
    会被改为 一个减号!!!

    --cacert ca.crt
    这样写才是正确的参数。 但不能复制。你需要输入英文字符的减号。喝喝。

    Reply

    lizongbo reply on 二月 15th, 2009:

    嗯,确实这样,不知道是wordpress还是其插件做了什么处理,
    一些url也替换成了escaped_anchor这样的东西,我懒得处理了。

  3. jqk 说道:

    非常感谢.我总是感觉自己在加密和认证这里基础知识不过关!

    我试了windows下的curl 是好用的.我的命令行里不是这个参数.
    -cacert ca.crt 查了一下 help应该是这个参数.
    –cacert ca.crt
    linux下的help里也是这个参数. 但我没有实际进行测试.

    再次感觉. 8-)

    Reply

  4. goffee 说道:

    谢谢。我再从这方面继续查找下。

    Reply

  5. goffee 说道:

    你好,
    我在linux下使用curl也出现了问题。
    问题如下:
    在linux或winodws浏览器运行含有curl的php文件是正常的(所谓得前台运行)。但是在linux后台用php命令执行相同得php文件却一直报“段错误”。在测试中,发现只有https的地址才会出现此问题,http则正常运行的。
    服务器得配置是:
    redhat linux AS4
    TOMCAT5.5
    APACHE2.0.59
    PHP5.2.6
    希望能得到你得帮助。谢谢。

    Reply

    lizongbo reply on 一月 8th, 2009:

    不好意思,我没在linux下试过,不过原理应该都是一样的,即导入配置客户端和服务端都可以信任的根证书。

  6. lizongbo 说道:

    to lw:
    你需要找到网站证书的根证书,并且导出成crt文件,才能使用–cacert ca.crt 这样的参数.
    而这个文件,除了系统内置的,其余的通常需要到 ca机构的网站去下载,
    例如szca的根证书下载页面为: http://www.szca.gov.cn:8081/jsp/web/Certificate.do

    我没有你的那种环境,我所测试的根证书也是我自己生成的,所以无法判断其它环境下的具体原因.

    Reply

  7. lw 说道:

    你好
    我现在使用CURL出现一点问题
    正好在你这里找到了原因
    非常感谢
    就是如果需要连接的网站使用的证书不是操作系统已经信任的证书,则需要指定ca根证书文件.
    并且服务器的证书CN必须与url里的host一致,否则无法下载.::
    这点
    出现的抱错就是curl https://www.618119.com/出现的错误一样
    但是我不知道如何解决这个错误,使用–cacert ca.crt指定方式也不行
    我在FEDORA环境下没有问题,将CURL移植到板子上就不行了,在板子上也可以下载到那种不需要证书的网页
    我的EMAIL:willie.lw@gmailcom
    希望得到您的指点 谢谢

    Reply

留下回复