c# - Stream to string -
how append stream output string instead of file in code?
httpwebresponse res = (httpwebresponse)httprequest.getresponse(); using (stream output = file.openwrite(@"c:\temp\tmp.html")) using (stream input = res.getresponsestream()) { byte[] buffer = new byte[8192]; int bytesread; while ((bytesread = input.read(buffer, 0, buffer.length)) > 0) { output.write(buffer, 0, bytesread); } input.close(); output.close(); }
you can use streamreader
:
httpwebresponse res = (httpwebresponse)httprequest.getresponse(); using (stream input = res.getresponsestream()) using (var streamreader = new streamreader(input)) { string result = streamreader.readtoend(); }
note read entire string
memory.
Comments
Post a Comment