473,395 Members | 1,412 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.

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.WebException: 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.Create(strURL);

oRequest.Timeout = 10000;
oRequest.UserAgent = "Web Client";

oResponse = (HttpWebResponse)oRequest.GetResponse();

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

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

strreturn = returnString.ToString();
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 4014
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 = (HttpWebResponse)oRequest.GetResponse();

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.supernews.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.WebException: 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.Create(strURL);

oRequest.Timeout = 10000;
oRequest.UserAgent = "Web Client";

oResponse = (HttpWebResponse)oRequest.GetResponse();

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

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

strreturn = returnString.ToString();
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
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...
5
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...
3
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
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...
2
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...
1
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...
1
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...
1
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....
4
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)...
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: 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
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,...
0
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,...
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...
0
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...

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.