简体   繁体   中英

POST request through Guzzle php

hi i wanted to make a post request to dropbox.i found there is this guzzle which can be easily send http req using php. here the http code given by dropbox

    `POST /2/files/list_folder
    Host: https://api.dropboxapi.com
    User-Agent: api-explorer-client
    Authorization: Bearer <access-token>
    Content-Type: application/json
    {
    "path": "",
    "recursive": false,
    "include_media_info": true,
    "include_deleted": false,
    "include_has_explicit_shared_members": false
    }`

This is my php code i coded for above request;

$response=$client->request('POST','https://api.dropboxapi.com',
[
    'headers'=>[
        'Authorization'=>'Bearer '.$API,
        'User-Agen'=>'api-explorer-client',
        'Content-Type'=>'application/json'
    ],
    'form_params'=>[

            'path'=>'',
            'recursive'=>'false',
            'include_media_info'=> 'true',
            'include_deleted'=> 'false',
            'include_has_explicit_shared_members'=> 'false'

    ]
]);

$headers = $response->getHeaders();
$body =$response->getBody();
$print=json_decode($body,true);
//Output headers and body for debugging purposes
var_dump($headers);echo"<br><br>";
var_dump($print);?>

this should give something similar to following ,but i get a small array

    {"entries": [
{
".tag": "folder",
  "name": "Photos",
  "path_lower": "/photos",
  "path_display": "/Photos",
  "id": "id:bwGPfg_v6ZUAAAAAAAAAOA"
},`

what i missed here? PS:im new to php related stuff :)

You are sending JSON, not an HTML form. So use 'json' instead of 'form_params' .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM