【问题标题】:I got a 500 error when I use guzzle but with curl I dont get one使用 guzzle 时出现 500 错误,但使用 curl 我没有得到
【发布时间】:2020-05-20 02:09:33
【问题描述】:

我在 PI 和 REST API 上有一个 Openhab 系统,我想在电视屏幕上显示信息。

我试过用 curl 来做这件事,它奏效了。所以现在我想对 Guzzle 做同样的事情。 首先,我只在 PC 的 Project 目录中安装了 composer 和 guzzle,然后我也在 PI 上安装了它们。两种方法都不起作用,因为我在两次尝试中都收到了 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;
}

我认为创建客户端会分解脚本

我需要你的帮助, 谢谢

【问题讨论】:

    标签: request guzzle openhab


    【解决方案1】:

    500 基本表示服务器出错。请附上成功的 cURL 命令(正如您在问题标题中提到的那样)。

    我还稍微修改了您的代码,以确保您正在处理响应的正文内容(->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();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2018-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多