如何添加自定义标题到https请求curl PHP脚本? [英] How to add the custom headers to https requesting curl PHP script?

查看:128
本文介绍了如何添加自定义标题到https请求curl PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在curl PHP脚本中,我们通过curl_setopt CURLOPT_HTTPHEADER 选项添加标题。

In curl PHP script, we add the headers by the curl_setopt CURLOPT_HTTPHEADER option. It works fine with HTTP request like search.yahoo.com but I tried it with the HTTPS request it doesn't work.

我已经禁用SSL对等验证,通过设置 CURLOPT_SSL_VERIFYPEER 选项为false。有办法实现吗?

I have disable SSL peer verification by setting CURLOPT_SSL_VERIFYPEER option to false. Is there way to implement it?

推荐答案

首先,您需要下载CA证书与您的浏览器,并将其保存为X .509。这将使您能够接受CA颁发的所有证书。然后使用以下CURL选项:

first of all you need to download the CA certificate with your browser and save it as X.509. This will make you able to accept all certificates issued by the CA. Then use the following CURL options:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "path_to_CA_certificate.crt");

CURLOPT_VERIFYHOST有不同的选项,你可以先尝试0以便检查CN检查,如果它工作然后尝试2。

CURLOPT_VERIFYHOST has different options, you can try 0 first in order to aviod CN check, and if it works then try with 2.

希望它有帮助。

这篇关于如何添加自定义标题到https请求curl PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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