Send GET HTTPS request with custom headers PHP

泪湿孤枕 提交于 2021-02-10 06:14:18

问题


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']);

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'));

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)

Thanks.


回答1:


You are missing a curl option for handling HTTPS request that is

CURLOPT_SSL_VERIFYPEER : FALSE to stop cURL from verifying the peer's certificate

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);


来源:https://stackoverflow.com/questions/42022695/send-get-https-request-with-custom-headers-php

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