zoukankan
html css js c++ java
ASP.NET获取HTML代码时的乱码问题
//
//
方法GetPageSource:获取指定网页的HTML代码
//
public
static
string
GetPageSource(
string
URL)
{
Uri uri
=
new
Uri(URL);
HttpWebRequest hwReq
=
(HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse hwRes
=
(HttpWebResponse)hwReq.GetResponse();
hwReq.Method
=
"
Get
"
;
hwReq.KeepAlive
=
false
;
//
将该属性设置为 true 以发送带有 Keep-alive 值的 Connection HTTP 标头。
//
应用程序使用 KeepAlive 指示持久连接的首选项。
//
当 KeepAlive 属性为 true 时,应用程序与支持它们的服务器建立持久连接。
//
注意 使用 HTTP/1.1 时,Keep-Alive 默认情况下处于打开状态。
//
将 KeepAlive 设置为假可能导致将 Connection: Close 标头发送到服务器。
StreamReader reader
=
new
StreamReader(hwRes.GetResponseStream(),System.Text.Encoding.GetEncoding(
"
gb2312
"
));
return
reader.ReadToEnd();
}
我写了这个方法从指定页面中获取HTML代码。
但当指定页面是UTF-8时,中文即出现乱码。
有什么办法知道指定页面使用的是什么编码?
如果指定页面本来就使用GB2312,我又把它转换为GB2312,会出现什么结果?
查看全文
相关阅读:
iOS NSUserDefaults 存储可变数组问题
iOS之[文件下载 / 大文件下载 / 断点下载]
macOS 新手开发:第 2 部分
iOS 游戏素材
iOS 动画
macOS 开发
iOS 之访问权限以及跳转到系统界面
蓝桥杯—ALGO-18 单词接龙(DFS)
蓝桥杯—ALGO-12 幂方分解(递归递推)
蓝桥杯—ALGO-131 Beaver's Calculator
原文地址:https://www.cnblogs.com/bankey/p/806869.html
最新文章
Whether this blog should be indexed by search engines
Whether to show the title field
Whether to show a related link box in the post composer
The BlogSpot subdomain under which to publish your blog
The number of the time stamp format
The time zone for this blog
Whether to show images in the Lightbox when clicked
2008浙大研究生复试热身赛2----畅通工程续
浙大计算机研究生复试上机考试2010年----最短路径问题
hdu2544最短路
热门文章
hdu1231最大连续子序列
Max Sum
hdu2097
hdu2087
Hat’s Words
Phone List
hdu1301 Jungle Roads
iOS 1 .Multiple commands produce 错误
苹果机型细节
iOS 中文件管理器的使用
Copyright © 2011-2022 走看看