TCP编程(3): WebRequest, WebResponse
/*--===------------------------------------------===---
WebRequest, WebResponse
许明会 23:51:45 2007年12月9日
--===------------------------------------------===---*/
using System;
using System.Net;
using System.Text;
using System.IO;
namespace xumh
{
public class runMyApp
{
static void Main()
{
string strUriBaidu = @"http://www.baidu.com";
WebRequest req = WebRequest.Create(strUriBaidu);
WebResponse res = req.GetResponse();
Stream srm = res.GetResponseStream();
System.Text.Encoding ec = Encoding.GetEncoding(936);
StreamReader sr = new StreamReader(srm,ec);
System.Text.StringBuilder sb =
new System.Text.StringBuilder();
char[] buff = new char[256];
int nCount = sr.Read(buff,0,256);
while(nCount>0)
{
sb.Append(new string(buff,0,nCount));
nCount = sr.Read(buff,0,256);
}
Console.WriteLine(sb.ToString());
//
}
};
}
WebRequest, WebResponse
许明会 23:51:45 2007年12月9日
--===------------------------------------------===---*/
using System;
using System.Net;
using System.Text;
using System.IO;
namespace xumh
{
public class runMyApp
{
static void Main()
{
string strUriBaidu = @"http://www.baidu.com";
WebRequest req = WebRequest.Create(strUriBaidu);
WebResponse res = req.GetResponse();
Stream srm = res.GetResponseStream();
System.Text.Encoding ec = Encoding.GetEncoding(936);
StreamReader sr = new StreamReader(srm,ec);
System.Text.StringBuilder sb =
new System.Text.StringBuilder();
char[] buff = new char[256];
int nCount = sr.Read(buff,0,256);
while(nCount>0)
{
sb.Append(new string(buff,0,nCount));
nCount = sr.Read(buff,0,256);
}
Console.WriteLine(sb.ToString());
//
}
};
}