代码
1 System.Net.WebRequest wReq = System.Net.WebRequest.Create("http://www.baidu.com");
2 // Get the response instance.
3 System.Net.WebResponse wResp = wReq.GetResponse();
4
5 System.IO.Stream respStream = wResp.GetResponseStream();
6 System.IO.StreamReader r = new System.IO.StreamReader(respStream, Encoding.GetEncoding("GB2312"));
7
8 string ddd=r.ReadToEnd();
9
10
2 // Get the response instance.
3 System.Net.WebResponse wResp = wReq.GetResponse();
4
5 System.IO.Stream respStream = wResp.GetResponseStream();
6 System.IO.StreamReader r = new System.IO.StreamReader(respStream, Encoding.GetEncoding("GB2312"));
7
8 string ddd=r.ReadToEnd();
9
10
代码
1 private void GetRequestCount(string url)
2 {
3 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
4 HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
5 Stream respStream = (Stream)resp.GetResponseStream();
6 Encoding encod = Encoding.Default;
7
8 StreamReader sr = new StreamReader(respStream, encod);
9
10 char[] chr = new char[256];
11
12 string content = "";
13
14 int count = sr.Read(chr, 0, 256);
15
16 while (count > 0)
17 {
18 String chrstring = new String(chr, 0, 256);
19 content += chrstring;
20 count = sr.Read(chr, 0, 256);
21 }
22
23 RequestTest.Text = content;
24 }
2 {
3 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
4 HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
5 Stream respStream = (Stream)resp.GetResponseStream();
6 Encoding encod = Encoding.Default;
7
8 StreamReader sr = new StreamReader(respStream, encod);
9
10 char[] chr = new char[256];
11
12 string content = "";
13
14 int count = sr.Read(chr, 0, 256);
15
16 while (count > 0)
17 {
18 String chrstring = new String(chr, 0, 256);
19 content += chrstring;
20 count = sr.Read(chr, 0, 256);
21 }
22
23 RequestTest.Text = content;
24 }

浙公网安备 33010602011771号