473,692 Members | 2,220 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 9680
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
11560
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
4923
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
9201
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
17386
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
2965
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
2614
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
1263
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
2371
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
7776
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
8604
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
9083
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
8961
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
8800
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
8801
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...
1
6459
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...
0
5819
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4324
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.