所以它的工作原理与HttpResponse对象类:HttpListenerResponse.AddHeader不喜欢非拉丁字符
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
(我们不得不编码为IE文件名) 但现在应该HttpListener做。它适用于IE。问题是Firefox和Chrome不会像解码编码IE标头值,但HttpResponse.AddHeader不允许非拉丁字符(代码System.Net):
if ((ch == '\x007f') || ((ch < ' ') && (ch != '\t')))
throw new ArgumentException(SR.GetString("net_WebHeaderInvalidControlChars"), "value");
我尝试使用反射来转转检查:
Type type = response.Headers.GetType();
PropertyInfo info = type.GetProperty("InnerCollection",
BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic);
NameValueCollection headers = (NameValueCollection)info.GetValue(response.Headers, null);
headers.Add(name, value);
没有东西上升,但该文件的名称已完全损坏。 我该怎么做才能使它工作?
从技术上讲,RFC 2616通过RFC 2045通过RFC 822将Content-Disposition文件名限制为US-ASCII。在[RFC 6266](http://tools.ietf.org/html/rfc6266#appendix-C.1)中也有一个说明。 – bzlm
所以我想知道,为什么它与HttpResponse一起工作?提琴手显示限制已被打破。 –