Webrequest and Timeout

  • Thread starter Christian Urbanczyk
  • Start date
C

Christian Urbanczyk

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
 
J

Jon Skeet [C# MVP]

Christian Urbanczyk said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top