日期:2014-05-18  浏览次数:21114 次

如何取得网页编码格式
我很郁闷 
因为我发现有些网页它根本不写编码方式,这个时候我又该怎么办啊 
1:http://shop.ebdoor.com/Shops/15495/CompanyCard.aspx 
源码里没有编码编码方式,但显示时UTF-8 
2:http://www.chaqy.com/qiye-njhjh/ 
源码里有编码编码方式: <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />但是显示时为UTF-8 
3:http://www.mai-miao.com/Web/Info/Detail.aspx?id=16998 
源码里没有编码编码方式,但显示时gb2312

不要告诉我
string encoding = webResponse.CharacterSet; 

string ctype = httpWebResponse.ContentType;


string ctypeLower = response.Headers["content-type"]; 

试过了,不好用

------解决方案--------------------
1.http://shop.ebdoor.com/Shops/15495/CompanyCard.aspx 
返回的http头:
HTTP/1.1 200 OK
Proxy-Connection: close
Connection: close
Content-Length: 18063
Via: 1.1 MSSZISA02
Date: Fri, 04 Dec 2009 06:34:28 GMT
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
p3p: policyref="/w3c/p3p.xml",CP="NOI DSP LAW NID PSA ADM OUR IND NAV"
X-AspNet-Version: 2.0.50727
Set-Cookie: ASP.NET_SessionId=fxiy2c45y30boy55oasz4m55; domain=ebdoor.com; path=/; HttpOnly
Cache-Control: private

2.http://www.chaqy.com/qiye-njhjh/
返回的http头:
HTTP/1.1 200 OK
Proxy-Connection: close
Connection: close
Content-Length: 7008
Via: 1.1 MSSZISA02
Date: Fri, 04 Dec 2009 06:46:46 GMT
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private

3.http://www.mai-miao.com/Web/Info/Detail.aspx?id=16998
返回的http头:
HTTP/1.1 200 OK
Proxy-Connection: close
Connection: close
Content-Length: 44742
Via: 1.1 MSSZISA02
Date: Fri, 04 Dec 2009 06:48:04 GMT
Content-Type: text/html; charset=gb2312
Server: Microsoft-IIS/7.0
Cache-Control: private
X-AspNet-Version: 2.0.50727
Set-Cookie: ASP.NET_SessionId=bsjetr553jehslnu4krlk555; path=/; HttpOnly
X-Powered-By: ASP.NET
X-UA-Compatible: IE=EmulateIE7

从上面信息可以看出,三个网站的http头里都有Content-Type: text/html; charset=XXX
全都含有编码信息