c# - HttpWebResponse.LastModified 的默认值

标签 c# .net httpwebresponse

记录在案here HttpWebResponse 类的 LastModified 属性:

contains the value of the Last-Modified header received with the response

根据此处和在线其他页面上的一些其他答案(例如 here):

It's completely up to the server if it sets the Last-Modified response header

如果服务器未设置此 header ,我应该期望该属性的值在 .Net 中是什么?日期时间.MinValue?日期时间。现在?或者是否有其他方法可以检测服务器是否设置了此 header ?

最佳答案

如果您查看 HttpWebResponse 的源代码您会看到,如果服务器未设置 Last-Modified header ,则返回 DateTime.Now

为了确定响应中是否存在 header 值,您可以使用 HttpWebResponse.GetResponseHeader方法。例如

var isLastModifiedSent = !string.IsNullOrEmpty(webResponse.GetResponseHeader("Last-Modified"));

关于c# - HttpWebResponse.LastModified 的默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42577127/

相关文章:

c# - NHibernate:在不使用第二个类的情况下映射一对多关系以填充集合

c# - 正则表达式忽略嵌套分隔符上的匹配

.net - 我需要处理任务吗?

.net - 如何使用自定义 WebResponse 创建 WebException

c# - 带空格的 WPF/XAML ResourceDictionary

c# - 我正在尝试使单声道 android 简单 "hello world"但我在模拟器中看不到 "hello world"为什么?

c# - 在 protobuf-net 中序列化 Type 类?

c# - 如果项目是由 SharpDevelop 生成的,则 OpenFileDialog 会被 Norton Antivirus 阻止

c# - 如何测试用 ASP.Net 编写的网站是否还活着?

asp.net - C# 中的简单服务器和客户端请求/响应