C# 为什么我能';是否无法通过WebClient阅读此下载页面的响应者?
这是我想分析的页面(它是iso-8859-1): 因此,如果您查看源代码:C# 为什么我能';是否无法通过WebClient阅读此下载页面的响应者?,c#,.net,character-encoding,webclient,C#,.net,Character Encoding,Webclient,这是我想分析的页面(它是iso-8859-1): 因此,如果您查看源代码: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 但它显示: Content-Length: 22967 Content-Type: text/html Date: Fri, 17 Jan 2014 14:24:17 GMT Expires: Fri, 17 Jan 2014 14:24:16 GMT Se
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
但它显示:
Content-Length: 22967
Content-Type: text/html
Date: Fri, 17 Jan 2014 14:24:17 GMT Expires: Fri, 17 Jan 2014 14:24:16 GMT
Set-Cookie: Lang=1; expires=Fri, 16-Jan-2015 23:00:00 GMT; path=/,ASPSESSIONIDACCAQTTC=PGGNBKJAHLBBCMELCOMHMHJG; path=/
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Cache-control: private
内容类型是text/html
。它已丢失iso-8859-1
为什么??我怎样才能得到它呢?如果你想得到字符集值(页面编码),你可以试试这个
Encoding encoding = null;
using (WebClient client = new WebClient())
{
string html = client.DownloadString(websiteUrl);
encoding = doc.DetectEncodingHtml(html);
}
Content-Length: 22967
Content-Type: text/html
Date: Fri, 17 Jan 2014 14:24:17 GMT Expires: Fri, 17 Jan 2014 14:24:16 GMT
Set-Cookie: Lang=1; expires=Fri, 16-Jan-2015 23:00:00 GMT; path=/,ASPSESSIONIDACCAQTTC=PGGNBKJAHLBBCMELCOMHMHJG; path=/
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Cache-control: private
Encoding encoding = null;
using (WebClient client = new WebClient())
{
string html = client.DownloadString(websiteUrl);
encoding = doc.DetectEncodingHtml(html);
}