php-cmis-client icon indicating copy to clipboard operation
php-cmis-client copied to clipboard

Invalid form encoding! for simple query

Open jbouzekri opened this issue 5 years ago • 0 comments

I have an Alfresco 9.0.0 installation and I am simply trying to get all the documents.

$httpInvoker = new \GuzzleHttp\Client(
    array(
        'defaults' => array(
            'auth' => array(
                CMIS_BROWSER_USER,
                CMIS_BROWSER_PASSWORD
            )
        )
    )
);

$parameters = array(
    \Dkd\PhpCmis\SessionParameter::BINDING_TYPE => \Dkd\PhpCmis\Enum\BindingType::BROWSER,
    \Dkd\PhpCmis\SessionParameter::BROWSER_URL => CMIS_BROWSER_URL,
    \Dkd\PhpCmis\SessionParameter::BROWSER_SUCCINCT => false,
    \Dkd\PhpCmis\SessionParameter::HTTP_INVOKER_OBJECT => $httpInvoker,
);

$sessionFactory = new \Dkd\PhpCmis\SessionFactory();

// If no repository id is defined use the first repository
if (CMIS_REPOSITORY_ID === null) {
    $repositories = $sessionFactory->getRepositories($parameters);
    $parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = $repositories[0]->getId();
} else {
    $parameters[\Dkd\PhpCmis\SessionParameter::REPOSITORY_ID] = CMIS_REPOSITORY_ID;
}

$session = $sessionFactory->createSession($parameters);
$result = $session->query('SELECT * FROM cmis:document');

It errored with :

{"exception":"invalidArgument","message":"Invalid form encoding!"}

This is the generated url and it makes a POST on it : /alfresco/api/-default-/public/cmis/versions/1.1/browser?cmisaction=query&statement=SELECT%20%2A%20FROM%20cmis%3Adocument&searchAllVersions=false&includeAllowableActions=true&renditionFilter=cmis%3Anone&skipCount=0&dateTimeFormat=simple&includeRelationships=none&maxItems=100

I found this article https://stackoverrun.com/ru/q/11802324 which says if you are doing POST, you should put the request in the body, not the url.

And indeed, if I do a curl http://mydomain/alfresco/api/-default-/public/cmis/versions/1.1/browser -d 'cmisaction=query&statement=SELECT%20%2A%20FROM%20cmis%3Adocument&searchAllVersions=false&includeAllowableActions=true&renditionFilter=cmis%3Anone&skipCount=0&dateTimeFormat=simple&includeRelationships=none&maxItems=100' it works great.

jbouzekri avatar Oct 07 '20 21:10 jbouzekri