I am wondering if there is a way to be 100% certain the httpwebrequest/response is cleared so that each time it retrieves the web source, it is fresh source and not cached (or old)?
Here is the code I am currently using:
Thanks in advance
Here is the code I am currently using:
VB.NET:
Public Function GetDataFromURL(ByVal sURL As String) As String
GetDataFromURL = String.Empty
Debug.Print("*GetDataFromUrl: started")
Dim NewHTML As String = String.Empty
sURL = Trim(sURL)
Try
Dim oReq As System.Net.HttpWebRequest
Dim oResp As System.Net.HttpWebResponse
oReq = System.Net.HttpWebRequest.Create(sURL)
With oReq
.Referer = RandomReferer()
.UserAgent = RandomUserAgent()
.Timeout = 30000
.KeepAlive = False
.AllowWriteStreamBuffering = True
End With
oResp = oReq.GetResponse
Dim sr As New IO.StreamReader(oResp.GetResponseStream)
Return sr.ReadToEnd
Catch ex As Net.WebException
Debug.Print("*WebException: " & ex.Message)
If ex.Status = Net.WebExceptionStatus.ProtocolError Then
Debug.Print("*Status Code: {0}", CType(ex.Response, Net.HttpWebResponse).StatusCode)
Debug.Print("*Status Description: {0}", CType(ex.Response, Net.HttpWebResponse).StatusDescription)
Dim strError As New System.Text.StringBuilder
With strError
.Append(My.Computer.Clock.LocalTime.ToString.Trim)
.Append(": ")
.Append(ex.Message.Trim)
End With
' ## Show the user the last 5 errors while attempting to retrieve source (Unfinished)
'frmMain.ToolStripMenuItem2.Text = strError.ToString
'frmMain.ToolStripMenuItem2.Image = frmMain.ImageList1.Images(3)
End If
Catch ex As Exception
Return String.Empty
Debug.Print("*Error Fetching URL Data: " & ex.Message)
Finally
Debug.Print("*GetDataFromUrl: ended")
End Try
End Function
Thanks in advance