Home > Backend Development > PHP Tutorial > PHP curl implements http and https request examples_PHP tutorial

PHP curl implements http and https request examples_PHP tutorial

WBOY
Release: 2016-07-13 10:17:09
Original
1148 people have browsed it

Example of php curl implementing http and https requests

Every time you want to use curl, you always have to check a lot of information.

Now save a few frequently used sentences to save you from having to go to Google every time.

Regular curl request:

 代码如下  
$url = 'http://www.111cn.net';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
var_dump($data);

Use curl to request HTTPS:

 代码如下  
$url = 'https://www.111cn.net';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
$data = curl_exec($curl);
curl_close($curl);
var_dump($data);

Attention

When requesting https data, a certificate will be required. At this time, add the following two parameters to avoid SSL certificate checking

 代码如下  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/895094.htmlTechArticlephp curl implements http and https request examples. Every time you want to use curl, you always have to check a lot of information. Now save a few frequently used sentences to save you from having to Google them every time. Regular curl request: ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template