当 header Last-modified 包含“Fri, 20 Nov 2009 15:53:16 E. Australia Standard Time”时,request.GetResponse() 会给出 ProtocolViolationException。
Q1 - 这是 .net 中的错误,还是我用于测试的网络服务器( Mongoose< /a> ) 没有以应有的格式服务器上的 Last-Modified 标头字段?
所以在 C# VS2008 中如果我拨打电话:
response = (HttpWebResponse)request.GetResponse();
Console.Out.WriteLine(" - LM = " + response.LastModified);
我得到:ProtocolViolationException:标头中日期字符串的值无效
当我使用 HTTPLiveHeaders 查看上次修改的 HTTP 标头时,我看到:
Last-Modified: Fri, 20 Nov 2009 15:53:16 E. Australia Standard Time
Q2 - 关于如何处理的任何建议,以便我依赖使用 Mongoose 服务器的单元测试不会出现此问题?
Q3 - 有人知道这是否会在生产互联网 Web 服务器上经常发生吗?即我是否应该假设某些网络服务器将以 .net 会犹豫的不同格式返回“Last-Modified”字段?
Q1 - Is this a bug in .net, or is the webserver I'm using for testing ( Mongoose ) not server up the header field Last-Modified in the format it should?
So in C# VS2008 if I make the call:
response = (HttpWebResponse)request.GetResponse();
Console.Out.WriteLine(" - LM = " + response.LastModified);
I get: ProtocolViolationException: The value of the date string in the header is invalid
When I use HTTPLiveHeaders to look at the HTTP head for last-modified I see:
Last-Modified: Fri, 20 Nov 2009 15:53:16 E. Australia Standard Time
Q2 - Any suggestions on how to handle so my unit tests which rely on using the Mongoose server won't have this issue?
Q3 - Anyone know if this is something that could happen on production internet web servers a lot? i.e. should I be assuming some webservers will give the Last-Modified field back in a different sort of format that .net will balk at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,除 GMT 之外的任何时间都是无效的:
“所有 HTTP 日期/时间戳都必须以格林威治标准时间 (GMT) 表示,无一例外。” (参见 RFC 2616,第 3.3.1 节,第 5 段)
Actually, anything but GMT is invalid:
"All HTTP date/time stamps MUST be represented in Greenwich Mean Time (GMT), without exception." (see RFC 2616, Section 3.3.1, Paragraph 5)
Q1)
如果您参考 RFC 2616 第 14 节,您'您会看到 Last-Modified 标头的定义是:
HTTP-date 已指定 在同一 RFC 中,第 3 节。
由于标头中的日期与第一个字段匹配,只有时区看起来不同,因此您可以检查 RFC 1123 看看它是否合法。关于时区,这是这样规定的。
从RFC 822第5节我们可以看到zone的定义:
由于标头中的时区未在此处列出,因此我们可以得出结论,它是无效的,并且服务器实际上违反了协议,因此该异常看起来是合理的。
Q2)
恐怕我不知道你如何处理它,除了以修复标头有效的方式放置代理,或者要求编写/维护 Mongoose 服务器的人修复它(或修复自己修改并提交补丁,因为它是一个开源项目)。
Q3)
我很少(如果有的话)看到 .NET 调用时出现问题的 Web 服务器,所以我不认为这种类型的问题在互联网上普遍存在。
Q1)
If you refer to the RFC 2616 Section 14, you'll see that the definition of the Last-Modified header is:
HTTP-date is specified in the same RFC, section 3.
Since the date in your header matches the first of these, with only the time zone looking different, you can check RFC 1123 to see if it's legal. Regarding time zones, this states.
From RFC 822 Section 5 we can see the definition of the zone:
As the time zone in the header is not listed here, we can therefore conclude that it is invalid, and that the server is in fact violating the protocol, so the exception appears reasonable.
Q2)
I'm afraid I don't know how you could handle it other than putting a proxy in the way that fixes up the header to be valid, or ask the people who write/maintain the Mongoose server to fix it (or fix it yourself and submit a patch, as it's an open source project).
Q3)
I've rarely (if ever) seen a web server that .NET has had problems calling, so I don't believe this type of issue is common on the internet in general.