为什么我的 httpresponsemessage 的内容 headers 没有添加到正确的字段?
Why are my httpresponsemessage's content headers not added to the correct field?
我正在尝试用 HttpClient
得到一个 data-stream,但是 HttpResponseMessage
发生了一些奇怪的事情,我回来了。
我发送请求的方式是这样的:
_webClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, _webClient.BaseAddress + connectionSuffix), HttpCompletionOption.ResponseHeadersRead);
然而,响应的 ContentHeaders 并未按照我期望的方式填充。这是一个示例:响应包含 Content-Type header 但在 ContentType 字段中找不到它的值,仅在泛型 Headers 中可枚举。
在 Wireshark 中分析数据包流给我以下信息:
>GET /video.cgi HTTP/1.1
Authorization: Basic YWRtaW46
Host: 192.168.0.150
Connection: Keep-Alive
回答:
>HTTP/1.0 200 OK
Server: Camera Web Server/1.0
Auther: Steven Wu
MIME-version: 1.0
Cache-Control: no-cache
Content-Type: multipart/x-mixed-replace;boundary=--video boundary--
这不是世界末日,我在边界参数之后,我可以在通用 Headers 字段中找到它。但我不禁要问:这是有意为之的行为吗?我似乎找不到任何关于 getting headers 的信息,只有关于如何将它们添加到请求中的信息(这是另一回事)
由于 boundary 参数值中的空格,此 header 的解析失败。
这不符合 RFC2616,因为 RFC 在 Section 2 中声明 header 参数值不得包含空格,否则应将其指定为带引号的字符串。
要么将边界更改为
boundary=--videoboundary--
或到
boundary="--video boundary--"
而且有效。
注意:您应该在读取后者的值时删除引号。
来自 RFC,第 2 节:(LWS = 线性白色 Space)
Many HTTP/1.1 header field values consist of words separated by LWS or
special characters. These special characters MUST be in a quoted string
to be used within a parameter value (as defined in section 3.6).
我正在尝试用 HttpClient
得到一个 data-stream,但是 HttpResponseMessage
发生了一些奇怪的事情,我回来了。
我发送请求的方式是这样的:
_webClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, _webClient.BaseAddress + connectionSuffix), HttpCompletionOption.ResponseHeadersRead);
然而,响应的 ContentHeaders 并未按照我期望的方式填充。这是一个示例:响应包含 Content-Type header 但在 ContentType 字段中找不到它的值,仅在泛型 Headers 中可枚举。
在 Wireshark 中分析数据包流给我以下信息:
>GET /video.cgi HTTP/1.1
Authorization: Basic YWRtaW46
Host: 192.168.0.150
Connection: Keep-Alive
回答:
>HTTP/1.0 200 OK
Server: Camera Web Server/1.0
Auther: Steven Wu
MIME-version: 1.0
Cache-Control: no-cache
Content-Type: multipart/x-mixed-replace;boundary=--video boundary--
这不是世界末日,我在边界参数之后,我可以在通用 Headers 字段中找到它。但我不禁要问:这是有意为之的行为吗?我似乎找不到任何关于 getting headers 的信息,只有关于如何将它们添加到请求中的信息(这是另一回事)
由于 boundary 参数值中的空格,此 header 的解析失败。
这不符合 RFC2616,因为 RFC 在 Section 2 中声明 header 参数值不得包含空格,否则应将其指定为带引号的字符串。
要么将边界更改为
boundary=--videoboundary--
或到
boundary="--video boundary--"
而且有效。
注意:您应该在读取后者的值时删除引号。
来自 RFC,第 2 节:(LWS = 线性白色 Space)
Many HTTP/1.1 header field values consist of words separated by LWS or
special characters. These special characters MUST be in a quoted string
to be used within a parameter value (as defined in section 3.6).