Home  >  Article  >  Backend Development  >  php curl 2 ways to get https request_PHP tutorial

php curl 2 ways to get https request_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:56:01827browse

php curl 2 ways to get https requests

  php curl 2 ways to get https requests

This article mainly introduces two methods for php curl to obtain https requests. This article gives code examples of two common practices: not verifying the certificate and host, and setting a correct certificate. Friends who need it can refer to it. Next

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

Obviously, there was a problem when verifying the certificate.

If you want to use curl to initiate a normal https request, there are two ways:

Method 1: Set not to verify the certificate and host.

Before executing 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 certificate is too old, causing the link to report an incorrect SSL certificate.

We need to download the new ssl local identification file

Place it in the program file directory

curl Add the following configuration

The code is as follows:

curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); ;

curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');

Done

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990993.htmlTechArticlephp curl 2 ways to get https requests php curl 2 ways to get https requests This article mainly introduces There are two methods for php curl to obtain https requests. This article gives the setting to not verify the certificate...
Statement:
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