本文整理汇总了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