Home  >  Article  >  Backend Development  >  php curl 2 ways to get https requests, curlhttps_PHP tutorial

php curl 2 ways to get https requests, curlhttps_PHP tutorial

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

php curl 2 ways to get https requests, curlhttps

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

Obviously, something went wrong while 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
Copy code 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

http://curl.haxx.se/ca/cacert.pem

Put it in the program file directory

curl adds the following configuration
Copy code 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)

If you are interested in this, you can read the article of a great foreign god. http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/990548.htmlTechArticlephp curl 2 ways to get https requests, curlhttps Today, a colleague reported that an error was reported when using curl to initiate an https request. : "SSL certificate problem, verify that the CA cert is O...
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