Very slow response *and* a timeout error with HttpWebRequest/HttpWebResponse



I have some code to connect to a website and pull some content out of the
HTML. I've verified that the 2 URLs I'm using are perfectly fine in
Internet Explorer and both of them return results "pretty quickly".

The first URL I try takes a while but eventually comes back with the correct
results. It took *much longer* than in Internet Explorer.
The second URL times out even if I increase the timeout value significantly.
Internet explorer didn't time out.

The first URL simply visits the main page.
The second URL is attempting to login (http - not https).

Any idea what might be wrong? I'll post my code below.

private string GetHTTP(string url)
string html;
HttpWebRequest req;
HttpWebResponse resp;

// Formulate the request
req = (HttpWebRequest)WebRequest.Create(url);
req.CookieContainer = new CookieContainer();
if (m_cookies != null && m_cookies.Count > 0)
// Add any previously saved cookies

// Get the response
resp = (HttpWebResponse)req.GetResponse();
if (resp.Cookies.Count > 0)
// Save off cookies for later use
m_cookies = resp.Cookies;

// Read the result
html = new StreamReader(resp.GetResponseStream(),

return html;

and then calling it with:
// Visit the site - sets up the initial cookies
// note: ""
// This takes much longer than Internet Explorer
html = GetHTTP(InitialURL);

// Login to the site
// note:
// This times out - even if I bump up the timeout value.
html = GetHTTP(LoginURL);

Upon a succesful login (2nd URL) in Internet Explorer, it is redirected
to a different URL. I'm assuming the timeout is because of that somehow.
If you want to experiment with the existing site, feel free to create an
account (it's for an event which is over already).






If you look at the form on the page, it's ACTION verb is POST. Your login is
attempting to do a GET.


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