[英]I got a 500 error when I use guzzle but with curl I dont get one
I have an Openhab system on a PI and a REST API and I want to display information on a TV-Screen.我在 PI 和 REST API 上有一个 Openhab 系统,我想在电视屏幕上显示信息。
I have tried to do it with a curl and it worked.我试图用卷曲来做它并且它起作用了。 So now I want to do the same with Guzzle.
所以现在我想对 Guzzle 做同样的事情。 First I only installed composer and guzzle in the Project directory on my PC, Then I also installed them on the PI.
首先我只在 PC 的 Project 目录中安装了 composer 和 guzzle,然后我也在 PI 上安装了它们。 Neither approach worked as I got a 500 error on both attempts.
这两种方法都不奏效,因为我在两次尝试中都出现了 500 错误。
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. 500
基本上意味着存在服务器错误。 Please attach the cURL command that is successful (as you mentioned in the question's title).请附上成功的 cURL 命令(如您在问题标题中提到的)。
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):我还稍微修改了您的代码,以确保您正在处理响应的正文内容(
->getBody()->getContents()
部分):
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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.