B
Brett
I'm checking a URL and logging the results returned from the server. One
problem is when a site ask for cookies, my code times out. For example, this
link does:
http://publications.mediapost.com/index.cfm?fuseaction=Articles.san&s=291719&Nid=12097&p=261023
A cookie prompt causes the following code to timeout and jump into the
catch. This causes me to miss providing values to those variables after the
"Dim wResp" line. How can I make use of the cookie or get around it to get
the status return codes from the server?
Try
TraceLink.URLSource = url
Dim wReq As WebRequest = WebRequest.Create(url)
Dim CookieContainer1 As New CookieContainer
wReq.Timeout = 10000
If TypeOf wReq Is HttpWebRequest Then
CType(wReq, HttpWebRequest).UserAgent = "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; Feedreader; .NET CLR 1.1.4322; .NET
CLR 2.0.40607)"
CType(wReq, HttpWebRequest).CookieContainer =
CookieContainer1
End If
Dim wResp As HttpWebResponse = DirectCast(wReq.GetResponse(),
HttpWebResponse) 'timeout occurs here
TraceLink.Server_StatusCode = wResp.StatusCode
TraceLink.Server_StatusDescription = wResp.StatusDescription
TraceLink.Server_ContentType = wResp.ContentType
TraceLink.URLDestination =
wReq.GetResponse.ResponseUri.AbsoluteUri
Catch ex As Exception
TraceLink.Server_StatusDescription = ex.Message()
End Try
Thanks,
Brett
problem is when a site ask for cookies, my code times out. For example, this
link does:
http://publications.mediapost.com/index.cfm?fuseaction=Articles.san&s=291719&Nid=12097&p=261023
A cookie prompt causes the following code to timeout and jump into the
catch. This causes me to miss providing values to those variables after the
"Dim wResp" line. How can I make use of the cookie or get around it to get
the status return codes from the server?
Try
TraceLink.URLSource = url
Dim wReq As WebRequest = WebRequest.Create(url)
Dim CookieContainer1 As New CookieContainer
wReq.Timeout = 10000
If TypeOf wReq Is HttpWebRequest Then
CType(wReq, HttpWebRequest).UserAgent = "Mozilla/4.0
(compatible; MSIE 6.0; Windows NT 5.1; Feedreader; .NET CLR 1.1.4322; .NET
CLR 2.0.40607)"
CType(wReq, HttpWebRequest).CookieContainer =
CookieContainer1
End If
Dim wResp As HttpWebResponse = DirectCast(wReq.GetResponse(),
HttpWebResponse) 'timeout occurs here
TraceLink.Server_StatusCode = wResp.StatusCode
TraceLink.Server_StatusDescription = wResp.StatusDescription
TraceLink.Server_ContentType = wResp.ContentType
TraceLink.URLDestination =
wReq.GetResponse.ResponseUri.AbsoluteUri
Catch ex As Exception
TraceLink.Server_StatusDescription = ex.Message()
End Try
Thanks,
Brett