I have an Openhab system on a PI and a REST API and I want to display information on a TV-Screen.
I have tried to do it with a curl and it worked. So now I want to do the same with Guzzle. First I only installed composer and guzzle in the Project directory on my PC, Then I also installed them on the PI. Neither approach worked as I got a 500 error on both attempts.
function getCurrentTemp() {
echo "test1";
$client = new GuzzleHttp\Client([
'base_uri'=>'http://fernseher/'
]);
echo "test2";
$return = $client->request('GET','http://openhab.clubdrei.com/rest/items/ThermostateTemp/state', ['auth' => ['User','Password']]);
echo $return;
}
I think the creating Client break up the script
I need your help, Thank you
500
basically means that there is a server error. Please attach the cURL command that is successful (as you mentioned in the question's title).
I also modified your code a bit, to be sure that you are are working with the body content of the response (->getBody()->getContents()
part):
function getCurrentTemp()
{
// You don't need 'base_uri' here, because you use absolute URL below
$client = new GuzzleHttp\Client();
$response = $client->request(
'GET',
'http://openhab.clubdrei.com/rest/items/ThermostateTemp/state',
['auth' => ['User','Password']]
);
return $response->getBody()->getContents();
}