gpt4 book ai didi

php - cURL 登录到 HTTPS 站点

转载 作者:可可西里 更新时间:2023-10-31 22:58:08 26 4
gpt4 key购买 nike

我一直在尝试使用 cURL 和 PHP 将登录凭据发布到 https 站点,但没有成功。对于不安全的站点,一切正常,但我无法使用 https 获取它。我知道我发布的标题详细信息是正确的(尽管我为了这个例子模拟了它们)。请帮忙。

    <?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. 将其上传到您的脚本可以看到的位置。
  3. 然后添加:

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

关于php - cURL 登录到 HTTPS 站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8318041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com