leancloud 的RESTAPI 通过php curl访问没有结果

WBOY
Release: 2016-06-06 20:35:56
Original
953 people have browsed it

根据leancloud的官方文档,用php里的curl来访问RESTAPI的时候,一直无法完成相应的功能,比如官方文档例子里创建一个GameScore的对象,php代码如下,设置好了访问url和appid等相关参数了,执行的时候最后只返回一个0,别的什么都没有,leancloud的控制台里看不到创建的对象,控制台里原来手动创建国GameScore 这个class

<code>php</code><code>$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;
</code>
Copy after login
Copy after login

回复内容:

根据leancloud的官方文档,用php里的curl来访问RESTAPI的时候,一直无法完成相应的功能,比如官方文档例子里创建一个GameScore的对象,php代码如下,设置好了访问url和appid等相关参数了,执行的时候最后只返回一个0,别的什么都没有,leancloud的控制台里看不到创建的对象,控制台里原来手动创建国GameScore 这个class

<code>php</code><code>$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;
</code>
Copy after login
Copy after login

坑爹的SSL

请问怎么解决的

LeanCloud 已经发布了官方的 php-sdk :https://github.com/leancloud/php-sdk ,对 REST API 有很好的封装,建议参考。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template