http://www.zhcw.com/lottery/db_table_1_desc.htm 是中彩网的一个普通页面,不过这个页面要正确的下载并显示却很有点意思,下面是代码
HttpWebRequest request
=
(HttpWebRequest)WebRequest.Create(
"
http://www.zhcw.com/lottery/db_table_1_desc.htm
"
);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String characterSet = response.CharacterSet;
if (characterSet == " ISO-8859-1 " ) // 注意字符集
{
characterSet = " gb2312 " ;
}
Stream stream;
if (response.ContentEncoding == " gzip " ) // 注意内容编码
{
stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
}
else
{
stream = response.GetResponseStream();
}
using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(characterSet)))
{
Console.Write(reader.ReadToEnd()); // OK了
}
response.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
String characterSet = response.CharacterSet;
if (characterSet == " ISO-8859-1 " ) // 注意字符集
{
characterSet = " gb2312 " ;
}
Stream stream;
if (response.ContentEncoding == " gzip " ) // 注意内容编码
{
stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
}
else
{
stream = response.GetResponseStream();
}
using (StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(characterSet)))
{
Console.Write(reader.ReadToEnd()); // OK了
}
response.Close();