1. Get the Stream
HttpWebRequest request= (HttpWebRequest) webrequest.create (URI);//Build HTTP request
request. Method = "Get";
HttpWebResponse response = (HttpWebResponse) hwr. GetResponse (); Make a request and get response
Resstream = Response. GetResponseStream (); Get the response stream
2. Read
1).The first way:
int count = (int) Response. ContentLength;
int offset = 0;
BUF = new Byte[count];
while (Count > 0)
{
int n = resstream.read (buf,offset,count);
if (n = = 0) break;
Count-= n;
offset + = n;
Console.WriteLine ("in Loop" + getString (BUF)); Number of test cycles
}
string content = Encoding.Default.GetString (buf, 0, buf. Length);
Read stream must be cycled, not read at once (Resstream.read (buf,0,count);), otherwise the read stream may be incomplete
2) Second way://Read stream with StreamReader
String content = "";
using (StreamReader sr = new StreamReader (Resstream))
{
Content = Sr. ReadToEnd ();
}
Two methods of reading HttpWebResponse flow and the problems of attention