YII2 use curl request, returns false

A cause:

Today, with yii framework, requests java interface always returns false.

Second, analysis of the course:

Use curl_error () method to print out Peer's Certificate issuer is not recognized.

Translated means ssl certificate not certified, certificate issue? Not pulling fine, judging by the results, it is the issue of the certificate.

But, after all, is a third-party interface, operation and maintenance to address the need to contact, view the certificate, but also re-certification path, a lot of trouble, hard to deal with.

Include set (not verified), incorporated by reference

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($curl,CURLOPT_CAINFO,dirname(__FILE__).'/cacert.pem');

III. Solution

Turn off the curl to verify the certificate. However curl class packages are unified, in order not to affect other code.

php curl turn off ssl validation: 

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//原生

$curl->setOption(CURLOPT_SSL_VERIFYPEER=>0);//YII2

In this process, also encountered the other side of the interface does not recognize the return json data

Solution set header

$curl->setHeaders(['Content-Type' => 'application/json']);

As a result, test again, the interface through.

Guess you like

Origin www.cnblogs.com/xiaommvik/p/11353411.html