View Single Post
  #20 (permalink)  
Old 08-30-2007, 09:56 AM
santhakumar santhakumar is offline
D-Web Genius
 
Join Date: Mar 2007
Posts: 927
santhakumar is on a distinguished road
Thumbs up Re: HTTP Web Response Exception - I cant able to trap.

That's just more code, not a program—is that code executed in a loop, is there any exception handling, etc.?



At least, make sure to wrap your code that uses the WebResponse and the response Stream in a C# using block:

Code:
using (WebResponse response = request.GetResponse())

using (Stream responseStream = response.GetResponseStream())

{

    // Read from responseStream

}
Note that if this is all you need to do from a networking perspective, you're better of using System.Net.WebClient, as it shields you from the chores of managing and disposing responses, streams etc.
Reply With Quote