473,763 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Cre ate(url);
req.CookieConta iner = new CookieContainer ();
if (m_cookies != null && m_cookies.Count 0)
{
// Add any previously saved cookies
//
req.CookieConta iner.Add(m_cook ies);
}

// Get the response
//
resp = (HttpWebRespons e)req.GetRespon se();
if (resp.Cookies.C ount 0)
{
// Save off cookies for later use
//
m_cookies = resp.Cookies;
}

// Read the result
//
html = new StreamReader(re sp.GetResponseS tream(),
Encoding.Defaul t).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(Initial URL);

// Login to the site
//
// note:
"http://www.warhorn.net/gilacon/login.do?WH_log inUsername=YYYY Y&WH_loginPassw ord=XXXXX"
// This times out - even if I bump up the timeout value.
html = GetHTTP(LoginUR L);
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 9694
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.Cre ate(url);
req.CookieConta iner = new CookieContainer ();
if (m_cookies != null && m_cookies.Count 0)
{
// Add any previously saved cookies
//
req.CookieConta iner.Add(m_cook ies);
}

// Get the response
//
resp = (HttpWebRespons e)req.GetRespon se();
if (resp.Cookies.C ount 0)
{
// Save off cookies for later use
//
m_cookies = resp.Cookies;
}

// Read the result
//
html = new StreamReader(re sp.GetResponseS tream(),
Encoding.Defaul t).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(Initial URL);

// Login to the site
//
// note:
"http://www.warhorn.net/gilacon/login.do?WH_log inUsername=YYYY Y&WH_loginPassw ord=XXXXX"
// This times out - even if I bump up the timeout value.
html = GetHTTP(LoginUR L);
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
11567
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 WebClient instance. WebClient* myWebClient = new WebClient(); // Apply ASCII Encoding to obtain the String* as a Byte array. Byte postArray= Encoding::ASCII->GetBytes(postData); myWebClient->Headers->Add(S"Content-Type",
9
4931
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 missing in response stream. The same search in the internet explorer shows all the characters. I am sending all the required headers with the HTTPWebrequest. Following code is used to get gogle results
0
9206
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 sure how to maintain this id over multiple requests. Here are my code: Globle Varibles private static int timeOut = 20000; private CookieContainer cookieContainer; /* other cookies */
5
17390
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. string get_url = "http://scmvs4:9090/gtccinfo/H485W020.HTML"; --url contains a form string post_url = "http://scmvs4:9090/cgi-bin/gticglnk/P485VEGA"; --called by get_Url upon submit
14
2974
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 well except when I try to download an attachment file from a web-based mailbox. I've tried using credentials and saving the cookies, nothing helps.
2
2616
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 XML to a website are also welcome. Many thanks, Steven
3
1267
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, which requires the use of IAsynchResult - besides other things. Does anyone have or can anybody point to code for this, please?! TIA Dim request As HttpWebRequest = CType(WebRequest.Create(MyUrl), HttpWebRequest) ' Set some reasonable limits...
1
2377
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! HttpWebRequest webreq = WebRequest.Create(WMSReq.ToString()) as HttpWebRequest; HttpWebResponse webrep = webreq.GetResponse()
7
7783
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 code: 'Creating the request and getting the response Dim theResponse As HttpWebResponse Dim theRequest As HttpWebRequest Try 'Checks if the file exist theRequest = WebRequest.Create(Me.Filelocation) ...
0
9566
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9389
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9943
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9828
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.