发送带有自定义标头PHP的GET HTTPS请求 [英] Send GET HTTPS request with custom headers PHP
问题描述
我想在PHP中使用自定义参数发送HTTPS请求.我尝试了curl方法:
I want to send a HTTPS request in PHP with custom parameters. I tried with curl method :
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://myurl.com/item/books');
curl_setopt($ch,CURLOPT_HEADER,array('Token: 888888888'));
$content = curl_exec($ch);
echo $content;
$info = curl_getinfo($ch);
print_r($info['request_header']);
我的问题是我的请求(GET)在HTTPS中,并且无法发送标头参数Token:888888.我尝试过:
My problem is that my request (GET) is in HTTPS and I can't send the header parameter Token: 888888. I have tried with:
curl_setopt($ch,CURLOPT_HTTPHEADER,array('Token: 888888888'));
它不起作用,因为我的请求是在HTPPS中进行的.我需要正确的方法来发送带有自定义标头的HTTPS请求.(Internet中的许多示例都是针对HTTP请求而非HTTPS的)
And it doesn't work because my request is in HTPPS. I need the proper method to send my HTTPS request with custom headers. (Many example in Internet are for HTTP request not HTTPS)
谢谢.
推荐答案
您缺少用于处理HTTPS请求的curl选项
You are missing a curl option for handling HTTPS request that is
CURLOPT_SSL_VERIFYPEER :FALSE阻止cURL验证对等方的证书
CURLOPT_SSL_VERIFYPEER : FALSE to stop cURL from verifying the peer's certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
这篇关于发送带有自定义标头PHP的GET HTTPS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!