如何添加自定义标题到https请求curl PHP脚本?

编程入门 行业动态 更新时间:2024-10-28 06:22:58
本文介绍了如何添加自定义标题到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 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脚本?

本文发布于:2023-06-05 01:10:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/508781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   脚本   标题   https   curl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!