【问题标题】:Guzzle + openHAB REST API: "cURL error 61: Unrecognized content encoding type. libcurl understands deflate, gzip content encodings "Guzzle + openHAB REST API:“cURL 错误 61:无法识别的内容编码类型。libcurl 理解 deflate、gzip 内容编码”
【发布时间】:2020-11-24 15:21:13
【问题描述】:

我在使用 Guzzle 和我的 openHAB 系统的 REST API 时遇到了一些问题。

我有一个全新的 Laravel 7 安装,我使用 Guzzle 从 openHAB API 检索事物。这适用于对/things 端点的 GET 请求。但是,当我尝试向特定的 Things-endpoint /things/UUID 发送请求时,我收到以下错误:

GuzzleHttp\Exception\RequestException 

cURL error 61: Unrecognized content encoding type. libcurl understands deflate, gzip content encodings. (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

我不确定这到底是什么意思。附件是调试模式下 Guzzle 请求响应的转储:

在 PHP 代码中实例化 Guzzle 客户端:

$this->guzzle_client = new \GuzzleHttp\Client([
    'base_uri' => $protocol.$this->server_hostname.':'.$this->server_port.'/rest/',
    'verify' => false,
    'auth' => [$this->server_username, $this->server_password],
    'debug' => true,
]);         

Guzzle 客户端的调试输出:

*   Trying 10.0.0.63...
* TCP_NODELAY set
* Connected to 10.0.0.63 (10.0.0.63) port 8080 (#0)
> GET /rest/things HTTP/1.1
Host: 10.0.0.63:8080
User-Agent: GuzzleHttp/6.5.5 curl/7.64.1 PHP/7.3.11
Authorization: Basic Og==

到目前为止一切顺利......现在问题来了:

触发错误的 Guzzle 请求:

$response = $this->api()->request('GET', 'things/'.$uid);

Guzzle 请求的调试输出:

* Found bundle for host 10.0.0.63: 0x7fafc9d7acb0 [can pipeline]
* Re-using existing connection! (#0) with host 10.0.0.63
* Connected to 10.0.0.63 (10.0.0.63) port 8080 (#0)
> GET /rest/things/zwave%3Adevice%3A23daaff0%3Anode7 HTTP/1.1
Host: 10.0.0.63:8080
User-Agent: GuzzleHttp/6.5.5 curl/7.64.1 PHP/7.3.11
Authorization: Basic Og==

< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Encoding: UTF-8
< Content-Length: 7386
< Server: Jetty(9.4.20.v20190813)
< 
* Unrecognized content encoding type. libcurl understands deflate, gzip content encodings.
* Closing connection 0

我不确定在这里做什么?对于 Guzzle 来说,从 openHAB API 中获取一些东西似乎是一件微不足道的事情,所以我不明白为什么这两个系统之间会出现编码问题。

知道如何解决这个问题吗?

【问题讨论】:

标签: php laravel guzzle openhab


【解决方案1】:

这不是你的错,而是服务器的错。

您从服务器获得的Content-Encoding: UTF-8 不正确。此标头 should contain transfer encoding type (like gzip or deflate),但不是字符集 (UTF-8)。

最好的选择是联系服务器的开发人员并在那里解决问题。在那之前你真的什么都做不了。

【讨论】:

    猜你喜欢
    • 2021-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 2018-02-27
    • 2021-10-16
    • 2019-05-25
    • 1970-01-01
    相关资源
    最近更新 更多