主代码EG:
WebHeaderCollection whc = new System.Net.WebHeaderCollection();
string urlf = "http://www.stats-sd.gov.cn/tjsj/ydsj.asp?zy=04&d1=2005&d2=03";
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(urlf);
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Accept = "text/html, application/xhtml+xml, */*";
myRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
whc.Add("Accept-Language", "zh-CN");
myRequest.Headers = whc;
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = null;
sr = new StreamReader(stream, Encoding.GetEncoding("GB2312"));
string content11 = sr.ReadToEnd();
response.Close();
stream.Close();
sr.Close(); content11 = ConvertToShiftJisH(content11);
方法:
private static string ConvertToShiftJisH(string content)
{
Encoding encoding = Encoding.GetEncoding("us-ascii");
Encoding en = Encoding.GetEncoding("GB2312");
byte[] source = Encoding.Default.GetBytes(content);
byte[] utf8 = Encoding.Convert(encoding, en, source);
string ss = Encoding.Default.GetString(utf8);
return ss;
}
盼大神指引明灯:编码 网页编码转换
WebHeaderCollection whc = new System.Net.WebHeaderCollection();
string urlf = "http://www.stats-sd.gov.cn/tjsj/ydsj.asp?zy=04&d1=2005&d2=03";
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(urlf);
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Accept = "text/html, application/xhtml+xml, */*";
myRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
whc.Add("Accept-Language", "zh-CN");
myRequest.Headers = whc;
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader sr = null;
sr = new StreamReader(stream, Encoding.GetEncoding("GB2312"));
string content11 = sr.ReadToEnd();
response.Close();
stream.Close();
sr.Close(); content11 = ConvertToShiftJisH(content11);
方法:
private static string ConvertToShiftJisH(string content)
{
Encoding encoding = Encoding.GetEncoding("us-ascii");
Encoding en = Encoding.GetEncoding("GB2312");
byte[] source = Encoding.Default.GetBytes(content);
byte[] utf8 = Encoding.Convert(encoding, en, source);
string ss = Encoding.Default.GetString(utf8);
return ss;
}
盼大神指引明灯:编码 网页编码转换
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货