According to the official leancloud documents, when using curl in php to access RESTAPI, the corresponding functions cannot be completed. For example, if you create a GameScore object in the official document example, the php code is as follows, after the access url and appid parameters are set, only one request is returned during execution... according to the official leancloud documents, when using curl in php to access RESTAPI, the corresponding functions cannot be completed. For example, if you create a GameScore object in the official document example, the php code is as follows, after the access url and appid parameters are set, only 0 is returned at the end of the execution, and nothing else exists. The created object cannot be seen in the leancloud console, in the console, the class GameScore is manually created.
php
$headers = array( 'Content-Type: application/json', 'X-AVOSCloud-Application-Id: '.$appID, 'X-AVOSCloud-Application-Key: '.$appKey ); $dataJson = json_encode( array( 'score' => 2015, 'playerName' => 'Tom Raidol', 'cheatMode'=> true ) ); $curlConn = curl_init(); curl_setopt($curlConn, CURLOPT_TIMEOUT, 30); curl_setopt($curlConn, CURLOPT_USERAGENT, 'AVOSCloud.com-php-library/2.0'); curl_setopt($curlConn, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlConn, CURLINFO_HEADER_OUT, true); curl_setopt($curlConn, CURLOPT_HTTPHEADER, $headers); curl_setopt($curlConn, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curlConn, CURLOPT_POSTFIELDS, $dataJson); curl_setopt($curlConn, CURLOPT_URL, $leancloudAPI); $response = curl_exec($curlConn); print_r($response); $responseCode = curl_getinfo($curlConn, CURLINFO_HTTP_CODE); echo $responseCode;
Reply content:
According to the official leancloud documents, when using curl in php to access RESTAPI, the corresponding functions cannot be completed. For example, if you create a GameScore object in the official document example, the php code is as follows, after the access url and appid parameters are set, only 0 is returned at the end of the execution, and nothing else exists. The created object cannot be seen in the leancloud console, in the console, the class GameScore is manually created.
php
$headers = array( 'Content-Type: application/json', 'X-AVOSCloud-Application-Id: '.$appID, 'X-AVOSCloud-Application-Key: '.$appKey ); $dataJson = json_encode( array( 'score' => 2015, 'playerName' => 'Tom Raidol', 'cheatMode'=> true ) ); $curlConn = curl_init(); curl_setopt($curlConn, CURLOPT_TIMEOUT, 30); curl_setopt($curlConn, CURLOPT_USERAGENT, 'AVOSCloud.com-php-library/2.0'); curl_setopt($curlConn, CURLOPT_RETURNTRANSFER, true); curl_setopt($curlConn, CURLINFO_HEADER_OUT, true); curl_setopt($curlConn, CURLOPT_HTTPHEADER, $headers); curl_setopt($curlConn, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curlConn, CURLOPT_POSTFIELDS, $dataJson); curl_setopt($curlConn, CURLOPT_URL, $leancloudAPI); $response = curl_exec($curlConn); print_r($response); $responseCode = curl_getinfo($curlConn, CURLINFO_HTTP_CODE); echo $responseCode;
Potholes SSL
How can this problem be solved?
LeanCloud has released the official php-sdk: https://github.com/leancloud/php-sdk, the rest api has a good encapsulation, recommended reference.