How to bypass website pops via HTTPWebRequest?

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
 
B

Brett

This problem is related to a connection limit that is defaulted to 2 in the
HttpWebRequest object:
Dim objRequest As HttpWebRequest = WebRequest.Create(url)

In the watches window, the tree looks like this:
ObjRequest
ServicePoint
ConnectionLimit = 2
CurrentConnection2 = 2

The resolution was:
wResp.Close()

Must I have access to the server "url" is referencing to change the
connection limit? How exactly is it done?

Thanks,
Brett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top