HttpResponseMessage.Content.Headers ContentDisposition为null [英] HttpResponseMessage.Content.Headers ContentDisposition is null

查看:1453
本文介绍了HttpResponseMessage.Content.Headers ContentDisposition为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下载使用文件HttpClient的,我先下载了头,然后内容。当头部被下载,我可以看到HttpResponseMessage的Content属性头采集,而是通过ContentDisposition页眉上访问它时,得到空

When downloading a file with HttpClient, I'm downloading first the headers and then the content. When headers are downloaded, I can see Headers collection on the Content property of HttpResponseMessage, but when accessing it through ContentDisposition on Headers, get null

为什么发生这种情况?菲德勒显示头都很好...

Why this is happening? Fiddler shows headers are fine...

代码:

var responseMessage = await httpClient.GetAsync(uri, 
HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(continueOnCapturedContext: false);



更新1



它看起来像这样类是按照 2616 所列内容处置实施和未办理内容处置实施更新的 RFC 6266 。 RFC 2616定义文件名参数值是一个的引用字符串的,其中更新RFC 6266只是指出它应该是的

Update 1

It looks like this class is following Content-Disposition implementation outlined in RFC 2616 and fails to handle Content-Disposition implementation update RFC 6266. RFC 2616 defines filename parameter value to be a quoted-string, where update RFC 6266 just states it should be value.

content-disposition = "Content-Disposition" ":"
                          disposition-type *( ";" disposition-parm )
    disposition-type = "attachment" | disp-extension-token
    disposition-parm = filename-parm | disp-extension-parm
    filename-parm = "filename" "=" quoted-string
    disp-extension-token = token
    disp-extension-parm = token "=" ( token | quoted-string )



RFC 6266语法



RFC 6266 Grammar

content-disposition = "Content-Disposition" ":"
                        disposition-type *( ";" disposition-parm )

 disposition-type    = "inline" | "attachment" | disp-ext-type
                     ; case-insensitive
 disp-ext-type       = token

 disposition-parm    = filename-parm | disp-ext-parm

 filename-parm       = "filename" "=" value
                     | "filename*" "=" ext-value

 disp-ext-parm       = token "=" value
                     | ext-token "=" ext-value
 ext-token           = <the characters in token, followed by "*">



其中, EXT值=< EXT-值,在[RFC5987定义],第3.2节>

工作情况

失败案例

掀开的与MS票连接。

微软已经承认,这是一个错误并会解决它。

Microsoft has acknowledged that this is a bug and will fix it.

推荐答案

问题是与尾随;在内容部署头

The problem is with the trailing ; in the content-disposition header

        [Fact]
        public void ParseContentDispositionHeader()
        {
            var value = ContentDispositionHeaderValue.Parse("attachment; filename=GeoIP2-City_20140107.tar.gz");
            Assert.Equal("GeoIP2-City_20140107.tar.gz",value.FileName);
        }

如果我添加了分号解析会失败。如果你看一下RFC6266语法,分号只应该先于参数。

If I add the semi-colon the parsing will fail. If you look at the RFC6266 grammar, the semi-colon is only supposed to precede the parameter.

这篇关于HttpResponseMessage.Content.Headers ContentDisposition为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆