本文整理汇总了VB.NET中System.Net.HttpWebRequest.IfModifiedSince属性的典型用法代码示例。如果您正苦于以下问题:VB.NET HttpWebRequest.IfModifiedSince属性的具体用法?VB.NET HttpWebRequest.IfModifiedSince怎么用?VB.NET HttpWebRequest.IfModifiedSince使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了HttpWebRequest.IfModifiedSince属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Uri
' Create a new 'Uri' object with the mentioned string.
Dim myUri As New Uri("http://www.contoso.com")
' Create a new 'HttpWebRequest' object with the above 'Uri' object.
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(myUri), HttpWebRequest)
' Create a new 'DateTime' object.
Dim targetDate As DateTime = DateTime.Now
targetDate.AddDays(-7.0)
myHttpWebRequest.IfModifiedSince = targetDate
Try
' Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
Console.WriteLine("Response headers for recently modified page" + ControlChars.Cr + "{0}" + ControlChars.Cr, myHttpWebResponse.Headers)
Dim streamResponse As Stream = myHttpWebResponse.GetResponseStream()
Dim streamRead As New StreamReader(streamResponse)
Dim readBuff(256) As [Char]
Dim count As Integer = streamRead.Read(readBuff, 0, 256)
Console.WriteLine(ControlChars.Cr + "The contents of Html Page are : " + ControlChars.Cr)
While count > 0
Dim outputData As New [String](readBuff, 0, count)
Console.Write(outputData)
count = streamRead.Read(readBuff, 0, 256)
End While
' Close the Stream object.
streamResponse.Close()
streamRead.Close()
' Release the HttpWebResponse Resource.
myHttpWebResponse.Close()
Console.WriteLine(ControlChars.Cr + "Press 'Enter' key to continue.................")
Console.Read()
Catch e As WebException
If e.Response IsNot Nothing
If CType(e.Response,HttpWebResponse).StatusCode = HttpStatusCode.NotModified
Console.WriteLine((ControlChars.Cr + "The page has not been modified since " + targetDate))
Else
Console.WriteLine(ControlChars.Cr + "Unexpected status code = " + Ctype(e.Response,HttpWebResponse).StatusCode)
End If
Else
Console.WriteLine(ControlChars.Cr + "Unexpected Web Exception " + e.Message)
End If
End Try
开发者ID:VB.NET开发者,项目名称:System.Net,代码行数:43,代码来源:HttpWebRequest.IfModifiedSince
注:本文中的System.Net.HttpWebRequest.IfModifiedSince属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论