How to add the custom headers to https requesting curl PHP script?

和自甴很熟 提交于 2020-01-17 02:56:06

问题


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.

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


回答1:


here is a quick solution add curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); before curl_exec()

here $ch curl_init() object;

Do refer here for alternative solution




回答2:


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 has different options, you can try 0 first in order to aviod CN check, and if it works then try with 2.

Hope it helps.



来源:https://stackoverflow.com/questions/24774221/how-to-add-the-custom-headers-to-https-requesting-curl-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!