Php curl: two methods for obtaining https requests

Source: Internet
Author: User

Php curl: two methods for obtaining https requests

Php curl: two methods for obtaining https requests

This article mainly introduces two methods for php curl to obtain https requests. This article provides code instances that are set to not verify the certificate and host, and set a correct certificate, for more information, see

Today, a colleague reported an error when using curl to initiate an https request: "SSL certificate problem, verify that the CA cert is OK. details: error: 14090086: SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed"

Obviously, a problem occurs during certificate verification.

Curl can be used in the following two ways:

Method 1: Do not verify the certificate and host.

Before you execute curl_exec. Set option

The Code is as follows:

$ Ch = curl_init ();

......

Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, FALSE );

Curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, FALSE );

Method 2: Set a correct certificate.

The local ssl identification certificate is too old, resulting in incorrect Link error ssl certificate.

We need to download the new ssl local discriminant file.

Put it in the program file directory

Add the following configuration for curl

The Code is as follows:

Curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, true );;

Curl_setopt ($ ch, CURLOPT_CAINFO, dirname (_ FILE _). '/cacert. pem ');

Success

(My Verification Failed... Error message: SSL certificate problem, verify that the CA cert is OK. Details: error: 14090086: SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed)

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.