473,748 Members | 7,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTPWebResponse Timeout problems

I thought I was doing a simple thing, here -- asking a server for a text
document, getting the first 150 lines, and then returning the lines. But
I keep getting timeout errors:

"Exception Details: System.Net.WebE xception: The operation has timed-out."

I read somewhere that generally these errors come from not closing a
HTTPWebResponse connection before opening another. But -- to my
knowledge -- I've shut down connections in every way I could, and I'm
still getting the errors.

I'd sure appreciate any pointers!

Here's my code:

=============== =============== ==========

public string getHeader (string strURL)
{
StringBuilder returnString = new StringBuilder() ;

String strreturn;
HttpWebResponse oResponse = null;
Stream myStream = null;
StreamReader sr = null;
string thisRow = "";

try
{

HttpWebRequest oRequest = (HttpWebRequest )WebRequest.Cre ate(strURL);

oRequest.Timeou t = 10000;
oRequest.UserAg ent = "Web Client";

oResponse = (HttpWebRespons e)oRequest.GetR esponse();

myStream = oResponse.GetRe sponseStream();
//capture first 150 lines

sr = new StreamReader(my Stream);
int i = 0;
while ((thisRow = sr.ReadLine()) != null)
{
if (i==150){break; }
thisRow = thisRow.Replace ("_"," ");
returnString.Ap pend(thisRow+"\ n");
i++;
}

strreturn = returnString.To String();
sr.Close();
myStream.Close( );
oResponse.Close ();

}
catch
{
strreturn = "0";
}

finally
{
if (sr != null){sr.Close( );}

if(myStream != null){myStream. Close();}

if(oResponse != null){oResponse .Close();}

}

return strreturn;

}
Nov 19 '05 #1
1 4034
Brent,

The entire web request is getting delivered before you display the first 150
lines. So you need to first receive the entire page you are scraping. How
long does that take? If it's more than the 10000 milisecond timeout
parameter you've set that would be the cause of the exception... You may
need to set your timeout higher.

To see if this is the problem set a breakpoint on the:

oResponse = (HttpWebRespons e)oRequest.GetR esponse();

line of code and then in the debugger see if that is returned or if it times
out.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11******** *****@corp.supe rnews.com...
I thought I was doing a simple thing, here -- asking a server for a text
document, getting the first 150 lines, and then returning the lines. But I
keep getting timeout errors:

"Exception Details: System.Net.WebE xception: The operation has timed-out."

I read somewhere that generally these errors come from not closing a
HTTPWebResponse connection before opening another. But -- to my
knowledge -- I've shut down connections in every way I could, and I'm
still getting the errors.

I'd sure appreciate any pointers!

Here's my code:

=============== =============== ==========

public string getHeader (string strURL)
{
StringBuilder returnString = new StringBuilder() ;

String strreturn;
HttpWebResponse oResponse = null;
Stream myStream = null;
StreamReader sr = null;
string thisRow = "";

try
{
HttpWebRequest oRequest = (HttpWebRequest )WebRequest.Cre ate(strURL);

oRequest.Timeou t = 10000;
oRequest.UserAg ent = "Web Client";

oResponse = (HttpWebRespons e)oRequest.GetR esponse();

myStream = oResponse.GetRe sponseStream();
//capture first 150 lines

sr = new StreamReader(my Stream);
int i = 0;
while ((thisRow = sr.ReadLine()) != null)
{
if (i==150){break; }
thisRow = thisRow.Replace ("_"," ");
returnString.Ap pend(thisRow+"\ n");
i++;
}

strreturn = returnString.To String();
sr.Close();
myStream.Close( );
oResponse.Close ();

}
catch
{
strreturn = "0";
}

finally
{
if (sr != null){sr.Close( );}

if(myStream != null){myStream. Close();}

if(oResponse != null){oResponse .Close();}

}

return strreturn;

}

Nov 19 '05 #2

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

Similar topics

0
2118
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits for a corresponding HTTPWebResponse. This works just fine. However, the timeout does not appear to apply to a BinaryReader created from the HTTPWebResponse. I’ve had instances where the procedures will hang indefinitely during the download. ...
5
36023
by: Nathan | last post by:
This is a copy of a message at microsoft.public.dotnet.framework.clr: THE CODE: I'm using an HttpWebResponse object to send an HTTP POST to a Java server I have written and are running on the same machine (for dev and testing). Here is the C# code snippet: 1 string clientAddr = "http://127.0.0.1:22225/"; 2 try 3 { 4 webreq = (HttpWebRequest)WebRequest.Create( clientAddr );
3
4665
by: Nuno Magalhaes | last post by:
Hello, In a simple thread I have a code like the one below: public void ProtectionRun() { while(true) { //Sleep thread for one minute //Thread.Sleep(60000); HttpWebRequest
2
2605
by: Noggin The Nog | last post by:
Hi all, I've been trying to get HttpWebResponse to work, but whenever I try I get "The operation has timed-out". I'm simply trying to send an HTTP request querystring to a remote website and read back the single string it returns (OK/Not-Ok)! It seems such a simple thing to do, but I've been on this for hours now! Here's the code I'm trying: Dim myRequest As HttpWebRequest Dim myResponse As HttpWebResponse
2
9690
by: GHS | last post by:
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...
1
3445
by: stewart.fay | last post by:
Dear all, I am using the HttpWebRequest and HttpWebRequest to send an XML request to an ASPX page. When I use the browser and add my XML request the request is posted fine and an answer is retrieved. However, when I use the code below I get an timeout error on the line: oWebResponse = DirectCast(oWebRequest.GetResponse, HttpWebResponse)
1
4337
by: daz_oldham | last post by:
Hi I have a method (very bottom of this post) which I am using for doing XMLRPC calls. This works fine locally in Cassini (debug mode in VS2005, WinXP SP2), however when I run this on my production server (MS Win 2k) I am getting the following socket error: System.Net.Sockets.SocketException: No connection could be made because
1
4389
by: Morgan Cheng | last post by:
I found one issue about HttpWebResponse. I tried to get a huge webpage (i.e. http://wx.msn.com) with HttpWebRequest timeout set; reading the response stream is still controlled by timeout. However, the HttpWebResponse.Close takes ages. I suppose HttpWebResponse want to do a clean resouce clean-up. So, if the website doen't finish sending chuckes of HTTP packets, the client would not return from Close(). Is there anybody clear about the...
4
3084
by: Dean Rettig | last post by:
I am using HttpWebRequest to get an HttpWebResponse from an https:// site. I am using cookies and certificates and everything seems to be working properly EXCEPT... The largest (html) document that I am trying to read is about 28788 bytes when downloaded using Firefox but when my dotnet app tries to retrieve it, the response is only about
0
8991
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
9541
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
9370
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
9321
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
9247
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
8242
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...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
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
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.