【问题标题】:HTTP: Illegal chunked encodingHTTP:非法分块编码
【发布时间】:2016-04-08 04:31:21
【问题描述】:

我有一个 .NET 客户端应用程序,它使用第三方库通过 http 访问服务器。该库抛出以下错误:

The server committed a protocol violation. Section=ResponseBody Detail=Response chunk format is invalid

该软件已经安装了几十次,所以我认为这一定是客户系统的问题,我怀疑是代理之间的问题。

我使用 Fiddler 获得了第一个提示。在嗅探 Fiddler 时注意到协议违规:

Illegal chunked encoding. 'MIME-Version: 1.0' is not a hexadecimal number.

Fiddler 显示以下响应:

MIME-Version: 1.0
Content-Type: Multipart/Related; boundary=MIME_boundary_RsidtvFKHs9ymusS/NI6l56qcD8r76ye; type=text/xml

--MIME_boundary_RsidtvFKHs9ymusS/NI6l56qcD8r76ye
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <osci@message>
Content-Length: 1545

<?xml version="1.0" encoding="UTF-8"?>

<soap:Envelope xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ soapMessageEncrypted.xsd http://www.w3.org/2000/09/xmldsig# oscisig.xsd http://www.w3.org/2001/04/xmlenc# oscienc.xsd"><soap:Body><xenc:EncryptedData MimeType="Multipart/Related"><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"></xenc:EncryptionMethod><ds:KeyInfo><xenc:EncryptedKey><xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"></xenc:EncryptionMethod><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIID0jCCArqgAwIBAgIJAMg6MGbE+zZRMA0GCSqGSIb3DQEBDQUAMIGJMQswCQYDVQQGEwJERTEf
MB0GA1UECAwWTWVja2xlbmJ1cmctVm9ycG9tbWVybjERMA8GA1UEBwwIU2Nod2VyaW4xLDAqBgNV
BAoMI0NvbXB1dGVyLUJlcm

如您所见,响应意外停止。

有谁知道问题可能是什么或如何解决?

【问题讨论】:

  • 什么是 HTTP 标头?
  • 请求的头部如下: POST /osci-manager-entry/externalentry HTTP/1.0 Host: [the-host] Content-Length: 3984 Proxy-Connection: Keep-Alive 头部响应包含以下内容:HTTP/1.0 200 OK 日期:星期一,2016 年 1 月 4 日 12:10:31 GMT 传输编码:分块内容类型:文本/纯文本; charset=iso-8859-1 连接:保持活动状态

标签: http protocols mime chunked http-1.1


【解决方案1】:

请求的头部如下:

POST /osci-manager-entry/externalentry HTTP/1.0
Host: [the-host]
Content-Length: 3984
Proxy-Connection: Keep-Alive

响应的标题包含以下内容:

HTTP/1.0 200 OK
Date: Mon, 04 Jan 2016 12:10:31 GMT
Transfer-Encoding: chunked
Content-Type: text/plain; charset=iso-8859-1
Connection: Keep-Alive

该软件已经安装了几十次,所以我认为必须 是客户系统中的一个问题,我怀疑是代理 之间。

在这种情况下,问题很可能是由使用 HTTP/1.0 引起的。分块传输和 Keep-Alive 在 HTTP/1.0 中不是标准的。

在分块传输编码中,每个块应该start with a hexadecimal number 指示后面的块的大小。显然这里没有这个数字:Illegal chunked encoding. 'MIME-Version: 1.0' is not a hexadecimal number.

在 HTTP/1.0 中,Keep-Alive 和分块传输编码cannot be used together

HTTP/1.1 服务器也可以建立持久连接 收到 Keep-Alive 连接令牌后的 HTTP/1.0 客户端。 但是,无法与 HTTP/1.0 客户端建立持久连接 使用分块传输编码,因此必须使用 Content-Length 用于标记每条消息的结束边界。

【讨论】:

  • 是的,可以肯定的是,一个反向代理正在处理响应,它采用 第一个块并将其作为完整的 HTTP/1.0 响应传输,而不替换 Transfer-Encoding 标头通过Content-length 标头,并且不解析其他块。 代理。
  • 这正是我在 Danny_ds 的提示后得出的结论。我能够继承第三方库的类并实现一个可以工作的自定义传输模块。 @Danny_ds 非常感谢你
猜你喜欢
  • 1970-01-01
  • 2012-08-18
  • 2013-08-13
  • 2017-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多