Leancloud's RESTAPI access via phpcurl has no results

Source: Internet
Author: User
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.

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.