c# - Streamreader does not work when I close HttpWebResponse early -
uri targeturi = new uri(targeturl); httpwebrequest request = (httpwebrequest)httpwebrequest.create(targeturi); httpwebresponse response = (httpwebresponse)request.getresponse(); streamreader reader = new streamreader(response.getresponsestream()); string data = reader.readtoend(); response.close();
why above code work fine following not? notice close response in following code.
uri targeturi = new uri(targeturl); httpwebrequest request = (httpwebrequest)httpwebrequest.create(targeturi); httpwebresponse response = (httpwebresponse)request.getresponse(); streamreader reader = new streamreader(response.getresponsestream()); response.close(); string data = reader.readtoend();
closing response closes response stream well... streamreader
no longer has read from.
from documentation webresponse.close
:
the close method cleans resources used webresponse , closes underlying stream calling stream.close method.
Comments
Post a Comment