简体   繁体   English

内容处置 - 在邮件 header 中发现无效字符:'['

[英]Content-Disposition - an invalid character was found in the mail header: '['

I want to get filename from the url below.我想从下面的 url 获取文件名。 When parsing Content-Disposition header to extract the filename it throws an error System.FormatException: An invalid character was found in the mail header: '['.在解析 Content-Disposition header 以提取文件名时,它会引发错误System.FormatException: An invalid character was found in the mail header: '['. .The value of the header is like below. .header的值如下。 I don't want to replace these characters because the filename will be changed if I do.我不想替换这些字符,因为如果我这样做,文件名将被更改。 How can I fix it?我该如何解决?

Content-Disposition: attachment; filename*=UTF-8''[Saglamindir.net] Internet Download Manager.rar
Url: https://www17.zippyshare.com/d/qS76ZdES/29289/%5bSaglamindir.net%5d%20Internet%20Download%20Manager.rar

My Code:我的代码:

var cdHeader = response.Headers["Content-Disposition"];
if (!string.IsNullOrEmpty(cdHeader))
{
    var properFormat = Encoding.UTF8.GetString(Encoding.GetEncoding(1252).GetBytes(cdHeader));
    properFormat = HttpUtility.UrlDecode(properFormat);
    var disp = new ContentDisposition(properFormat);
    var temp = disp.FileName;
    return temp.ReplaceInvalidChars();
}

You can't use unescaped "[" or "]" here (they need percent-encoding).您不能在此处使用未转义的“[”或“]”(它们需要百分比编码)。 The relevant specs are RFC 6266 (Content-Disposition) and RFC 8187.相关规范是 RFC 6266 (Content-Disposition) 和 RFC 8187。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM