473,387 Members | 1,606 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,387 software developers and data experts.

Webrequest and Timeout

Hello!

I have a problem with the Webrequest. I've search everywhere to find an
answer but it seems that no one has the the problem before. So i hope
somebody can help me here!

Following Code:
_________________________________________
WebRequest wrq = WebRequest.Create(URL);
WebResponse wrs = wrq.GetResponse();
Stream strm = wrs.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.ASCII);
string line = sr.ReadLine();

while (line != null)
{
// here I do what i need with the line
line = sr.ReadLine();
}
__________________________________________

It works ONE TIME and then i get always a timeout. I tried everything, first
request is no problem.. The URL is not the problem, because it works with
all only one time...
I also tried another method for the request, but with the same problem:
__________________________________________
WebClient client = new WebClient();
Stream data = client.OpenRead(URL);
StreamReader reader = new StreamReader(data);
string line = "";
line = reader.ReadLine();

while( line != null)
{
// here I do what i need with the line
line = reader.ReadLine();
}
___________________________________________

Example:

I invoke the method with::

GetWebPage(URL);
GetWebPage(URL2);

Then I get just the information from URL. I get a timeout for URL2!
When i change them:

GetWebPage(URL2);
GetWebPage(URL);

Then I get just the information from URL2. I get a timeout for URL!
Thank you for any help!
Christian
Apr 16 '06 #1
1 2666
Christian Urbanczyk <pl****@gmx.net> wrote:
I have a problem with the Webrequest. I've search everywhere to find an
answer but it seems that no one has the the problem before. So i hope
somebody can help me here!


<snip>

You should close/dispose the StreamReader when you've finished with it,
and call Dispose on the WebResponse. You can use "using" statements to
help with both of these.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 16 '06 #2

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

Similar topics

5
by: C# Learner | last post by:
Is it possible to create a WebRequest instance and, instead of giving it a URI, give it an actual HTTP request? e.g.: GET / HTTP/1.1 Host: www.google.com CR LF CR LF Thanks in advance.
2
by: news.microsoft.com | last post by:
Hello I try to implement "retry" if connection to web ends with "time out". I want to give a chance to prolong waiting for response. The following code is taken from WebRequest.GetResponse()...
1
by: aaronfude | last post by:
Hi, I'm running the following code to read a URL into a string. When the url is offline, it times out after about 10 seconds regardless of what I set myRequest.Timeout to. Any suggestions? ...
4
by: Bob | last post by:
I've got to use the http protocol to communicate with another machine as part of a Web Service using HttpWebRequest and HttpWebResponse. As such, timing is important. When I create the...
3
by: Stephane | last post by:
Hi, I'm trying to use PayPal and its Instant Payment Notification. In short, when a payment is made, PayPal send a post to my server and I post it back to PayPal. I'm using WebRequest to do...
0
by: Gordon | last post by:
I use the following code to get source HTML. The second line seems to work when I get no response from a site. However, I want to stop the request if it's taking more than 20 - 30 seconds. I can't...
0
by: thomasabcd | last post by:
Hi, During the user's registration I wan't to geo-code an address using localsearchmaps.com/geo. For that purpose I use a webrequest like this: string url =...
3
by: Jonathan | last post by:
I appreciate anyone's insight on this as I am new to web programming with .NET. I have a simple method which I use to send various HTTP requests to a web server (snippet below). On the first...
2
by: kkb | last post by:
Hello! First, I'm sorry because of my english... I'll try to be understandable! I've got a strange problem using .NET 2003 C# and I haven't figured it out for a long time. I'm implementing an...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.