Php curl implements http and https requests, and phpcurlhttps requests

Source: Internet
Author: User
Tags ssl certificate

Php curl implements http and https requests, and phpcurlhttps requests

This article describes how to implement http and https requests using php curl. The details are as follows:

Generally, the php curl function group can help us pretend to be an adult and capture the website. Here are two examples: accessing an http webpage and accessing an https webpage, let's take a look.

Each time you use curl, you always need to check a bunch of data.
Now we can save a few frequently used sentences, saving every time we go to Google.

Common curl requests:

Copy codeThe Code is as follows: $ url = 'HTTP: // www.bkjia.com ';
$ 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:

Copy codeThe Code is as follows: $ url = 'https: // www.jb51.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 focus.
$ Data = curl_exec ($ curl );
Curl_close ($ curl );
Var_dump ($ data );

Note:

When requesting https data, the certificate is required. At this time, the following two parameters are added to avoid ssl certificate check.

Copy codeThe Code is as follows: curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https requests do not verify the certificate and hosts
Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE );

I hope this article will help you with PHP programming.


PHP uses CURL to submit POST data to https websites

The error message is that the https protocol is not supported.
Stackoverflow.com/..-https has saved me. Thank God.
There are spaces in front of https.

For https websites, you can use php curl to simulate get and post. Can you get the returned value?

Yes.
CURLOPT_PROTOCOLS
The bitfield of CURLPROTO _ * indicates. If enabled, the bitfield value limits the protocols that libcurl can use during transmission. This will allow you to support many protocols when compiling libcurl, but the restriction is only a subset of them that are allowed to be used. By default, libcurl uses all protocols supported by libcurl. See CURLOPT_REDIR_PROTOCOLS.
Available protocol options: CURLPROTO_HTTP, CURLPROTO_HTTPS, CURLPROTO_FTP, protocol, CURLPROTO_SCP, protocol, CURLPROTO_TELNET, CURLPROTO_LDAP, CURLPROTO_LDAPS, protocol, CURLPROTO_FILE, protocol, CURLPROTO_ALL

By the way, you can obtain the returned value.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.