473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

GHS
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
//
req.CookieContainer.Add(m_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(),
Encoding.Default).ReadToEnd();
resp.Close();

return html;
}

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

// Login to the site
//
// note:
"http://www.warhorn.net/gilacon/login.do?WH_loginUsername=YYYYY&WH_loginPassword=X XXXX"
// This times out - even if I bump up the timeout value.
html = GetHTTP(LoginURL);
Notes:
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).
Ideas/suggestions?

--GHS
Jul 1 '06 #1
2 9653
GHS,
If you look at the form on the page, it's ACTION verb is POST. Your login is
attempting to do a GET.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"GHS" wrote:
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
//
req.CookieContainer.Add(m_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(),
Encoding.Default).ReadToEnd();
resp.Close();

return html;
}

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

// Login to the site
//
// note:
"http://www.warhorn.net/gilacon/login.do?WH_loginUsername=YYYYY&WH_loginPassword=X XXXX"
// This times out - even if I bump up the timeout value.
html = GetHTTP(LoginURL);
Notes:
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).
Ideas/suggestions?

--GHS
Jul 2 '06 #2
GHS
DOH! It all works now after reworking for that.

Thanks,
GHS
Peter Bromberg [C# MVP] wrote:
GHS,
If you look at the form on the page, it's ACTION verb is POST. Your
login is
attempting to do a GET.
Peter

Jul 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Kueishiong Tu | last post by:
I have a url, I pass it to Webclient, and I get response without any problem. String* uriString = S"trade7.masterlink.com.tw/futures/QuotePrice.jsp"; String* postData = S""; // Create a new...
9
by: Mangesh | last post by:
hi, I am using HTTPWebrequest object to download google results. in the response stream I am not getting some foreign characters eg. If I search "signo de pregunta", all the spanish characters are...
0
by: Peter Qian | last post by:
Hi, I'm working on a windows form based program that can log into a web service (Apache based, https is used for auth). I was able to post the login data and obtain a sessionID. However I'm not...
5
by: Tammy | last post by:
Hi, I have an aspx app which needs to post data to a form and read the response. I am confused on whether I should be using the get_url using "POST" method or the post_url using "GET" method. ...
14
by: tomer | last post by:
Clear DayHello, I have implemented a download manger in .NET that overrides Internet Explorer's bult-in download manager. I using HttpWebRequest/Response to download the files. All is working...
2
by: steven | last post by:
I'm posting an XML-string to a website. I'm using the function below. The problem is that it is extremely slow and I get many time-outs. Does anyone have any solutions ? Other solutions to post an...
3
by: PeterK | last post by:
With the code below, which I copied from the MSDN, I am getting only part of the the web-page 'MyUrl' returned (this is a synchronoues access). My hunch is that I have to use asynchronous access,...
1
by: humbleaptience | last post by:
I have a php script that did this before, I want to move it to asp.net I am getting ~30kbps download speeds with this asp.net code. The php seems to be lightening fast. Help! ...
7
by: raids51 | last post by:
Hello, i have a program that downloads a file using the httpwebrequest/response, and it usually works, but sometimes it will freeze at a random part of the download without an error. here is the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.