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,会出现什么结果?
查看全文
相关阅读:
解决 minicom 不能接收键盘输入问题
Qt 使用tablib获取多媒体tag信息
博客园scribefire配置
Connection Manager简称connman
【转】使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录
ubuntu 更改U盘设备分区/dev/sdb4 标识
Qt 自动化测试Test cutedriver
在Sublime2/3中使用build命令编译TypeScript文件
移动端Web适配单位rem的坑
禁止保存,拖拽图片,禁用右键和F12
原文地址:https://www.cnblogs.com/bankey/p/806869.html
最新文章
websocket原理、为何能实现持久连接?
form表单无刷新提交
判断平衡二叉树
sass/scss 和 less对比
ReactJS和AngularJS对比
XMLHttpRequest Level2 新功能
React的Virtual DOM厉害了
VC学习笔记----log4cxx
EntityFramework 6 Tips
Visual Studio 2019 Debugging without Source Code
热门文章
C# String.Format Function && Syntactic Sugar
T-SQL触发器踩坑小计
Apache Directory Studio Tutorial
Visual Studio 2017 Add WSDL
Visual Studio 2017 无法启动,进程中却有devenv.exe运行的解决办法
ODP.Net Tips
Visual Studio 2019 Nuget Tips
在QML 中用javascritpt 将中文转换拼音,可以在音标
yoctoproject 地址
树莓派zero 使用usb串口连接
Copyright © 2011-2022 走看看