【问题标题】:cURL request work fine on server but wont work on my localhost:8080cURL 请求在服务器上工作正常,但不能在我的 localhost:8080 上工作
【发布时间】:2013-10-01 05:24:10
【问题描述】:

我创建了一个进程,让我登录我的#########.com 帐户。当我把它放在我的 FTP 上时,它就像一个魅力。

这就是问题

我在 localhost:8080 上的机器 (easyPHP) 上设置了 apache 本地服务器。 我还在我的机器上设置了一个 IIS 服务器的端口 --> localhost:80。

我的 cURL 请求不起作用。这是我的代码:

$lien = 'https://#########.com/login';
$postfields = array( 
    'username' => 'xxx',
    'password' => 'xxx'
);


$path_cookie = 'connexion.txt';
if (!file_exists(realpath($path_cookie))) touch($path_cookie);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $lien);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEJAR, realpath($path_cookie));

$return = curl_exec($curl);
echo($return);
echo 'error:' . curl_error($curl);
curl_close($curl);
}

首先:是的,我的服务器上安装了 cURL,我在 apache 服务器和 IIS 服务器之间做了一些其他 cURL 请求,一切正常。

其次:文件“connexion.txt”已创建好,但为空。

第三: ($return) 的回显没有响应,而在我的服务器上响应是“Object 已移至此处。

第四:是的,我读过这个主题,但对我没有多大帮助..

cURL not working

最后:当我尝试调试 cURL 请求时,错误是:

错误:SSL 证书问题:无法获取本地颁发者证书

谁能帮帮我?我会留在这里回答评论/测试/调试/回答等。

谢谢!

【问题讨论】:

  • 您可能正在使用带有自签名证书的 ssl,或者没有为 curl 提供相关的 CA 内容,以便它可以验证您的证书。

标签: php apache curl ssl


【解决方案1】:

您很可能根本没有使用证书,因此请使用 http 或尝试使用

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

【讨论】:

    【解决方案2】:

    将“CURLOPT_SSL_VERIFYHOST”设置为 false 不是一个好习惯。

    我建议您下载 CA 根证书包并告诉 PHP 在哪里可以找到它。

    1. 您可以通过download here找到它。
    2. 下载 .pem 并将其保存在您的 PHP 安装可以访问的位置 它。
    3. 将文件位置添加到您的 php.ini 中:curl.cainfo="C:\Xamp\php\cacert.pem"
    4. 重启服务器]

    工作已安全完成。


    字体:https://snippets.webaware.com.au/howto/stop-turning-off-curlopt_ssl_verifypeer-and-fix-your-php-config/

    【讨论】:

    • 终于在不禁用验证的情况下很好的解决了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    相关资源
    最近更新 更多