AnsweredAssumed Answered

Simple PHP acess with api not working

Question asked by clemens.zimmermann@tu-berlin.de on Feb 13, 2015
Latest reply on Feb 20, 2015 by clemens.zimmermann@tu-berlin.de

hello,

 

I don't get it working to acess the mse via php , please help !!

 

From the commandline , this works :

 

curl -i -k -u user:pass -H "Accept: application/json" http://<mse-ip>/api/contextaware/v1/v1/maps/count  -X GET

 

From PHP, this does not work:

 

    $url ='http://<mse-ip>/api/contextaware/v1/maps/count';
    $username='user';
    $password='pass';
    $req = new HttpRequest($url, HttpRequest::METH_GET);

 

    $header= array (
            'Accept' => 'application/json',
            'Authorization' =>  'Basic '.base64_encode ($username . ":" . $password) ,
            'User-Agent' => $_SERVER['HTTP_USER_AGENT'],
            'Accept-Language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'],
            'Expect' => '' );
    $req->setHeaders( $header );
    $response = $req->send();
    $res = $req->getResponseData();
    $response_headers = $req->getResponseHeader('')

 

I get the error : Fatal error: Uncaught exception 'HttpInvalidParamException' with message 'Empty or too short HTTP message

 

Has anyone an idea or a simple example how to use the Api via PHP

 

Best regards Clemens

Outcomes