cURL登录到HTTPS站点 [英] cURL Login to HTTPS site

查看:114
本文介绍了cURL登录到HTTPS站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用cURL和PHP没有运气,发布登录凭据到https网站。一切工作正常的不安全的网站,但我不能得到它与https。我知道我发布的标题详细信息是正确的(虽然我为了这个例子嘲笑他们)。请帮助。

I have been trying to post login credentials to an https site using cURL and PHP with no luck. Everything works fine for unsecured sites but I can't get it with https. I know the headers details that I am posting are correct (although I mocked them up for the sake of this example). Please help.

    <?php
    // Initialize cURL
    $ch = curl_init('https://secured-example.com/auth.asp');

    // Enable HTTP POST
    curl_setopt($ch, CURLOPT_POST, 1);

    // Use SSL 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

    // Set POST parameters
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=myUser&password=myPass');

    // Imitate classic browser's behavior - handle cookies
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // Execute 1st request
    $store = curl_exec($ch);

    // Set file to download
    curl_setopt($ch, CURLOPT_URL, 'https://secured-example.com/file.pdf');

    // Execute 2nd request (file download)
    $content = curl_exec($ch);

    curl_close($ch);

    ?>


推荐答案



  1. 将其上传到脚本可以看到的位置。

  2. 然后添加:

  1. Export the certificate.
  2. Upload it to where your script can see it.
  3. Then add:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/path/to/certificateCA.crt");


这篇关于cURL登录到HTTPS站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆