PHP Curl Implementation HTTP and HTTPS request instance

Source: Internet
Author: User
Tags curl ssl certificate

Every time you use curl, you always have to look up a bunch of data.

Now will be used to save a few sentences, the province every time to go to Google.

General Curl Request:

The code is as follows
$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:

The code is as follows
$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);//This is the point.
$data = curl_exec ($curl);
Curl_close ($curl);
Var_dump ($data);

Attention

When requesting data for HTTPS, a certificate is required, and the following two parameters are added to circumvent the SSL certificate check

The code is as follows
curl_setopt ($ch, Curlopt_ssl_verifypeer, FALSE); HTTPS request does not verify certificate and hosts
curl_setopt ($ch, Curlopt_ssl_verifyhost, FALSE);
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.