获得html页面的方法如下:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strURL = this.Page.Request.QueryString["FN"] ; // create a new uri object with the node's target
Uri myUri = new Uri(strURL) ; // create a new request to the above mentioned URL.
WebRequest myWebRequest = WebRequest.Create(myUri) ; // Set the ContentType property
myWebRequest.ContentType = "application/x-www-from-urlencoded" ; System.Text.Encoding.GetEncoding("GB2312");
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse = myWebRequest.GetResponse() ; // get response stream to a stream object
Stream streamResponse = myWebResponse.GetResponseStream() ; StreamReader streamRead = new StreamReader(streamResponse) ; string strResponse = streamRead.ReadToEnd() ; // show the stream to the table
this.Table1.Rows[0].Cells[0].InnerHtml = strResponse ; // Close the response to free resources.
myWebResponse.Close() ; }
**************************************************************************************
但是在页面上显示的时候,总文显示为乱码。大家有什么好意见,请帮帮忙好么?
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strURL = this.Page.Request.QueryString["FN"] ; // create a new uri object with the node's target
Uri myUri = new Uri(strURL) ; // create a new request to the above mentioned URL.
WebRequest myWebRequest = WebRequest.Create(myUri) ; // Set the ContentType property
myWebRequest.ContentType = "application/x-www-from-urlencoded" ; System.Text.Encoding.GetEncoding("GB2312");
// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse = myWebRequest.GetResponse() ; // get response stream to a stream object
Stream streamResponse = myWebResponse.GetResponseStream() ; StreamReader streamRead = new StreamReader(streamResponse) ; string strResponse = streamRead.ReadToEnd() ; // show the stream to the table
this.Table1.Rows[0].Cells[0].InnerHtml = strResponse ; // Close the response to free resources.
myWebResponse.Close() ; }
**************************************************************************************
但是在页面上显示的时候,总文显示为乱码。大家有什么好意见,请帮帮忙好么?
解决方案 »
- AJAX 下设置用户控件内的Session
- MySql的客户端问题
- 我都不知道这个问题该怎么写。。。。。。菜鸟发问,高手请支招。。。
- 关于在线打印,提供一个简单的工具
- asp.net连oracle81一定要装oracle客户端吗?急!!!
- 急求javascript引用webservice.htc操作WebService的问题,多帖求救了,解答者4帖分全给!!!!
- 送分小问题:如何设置页面?先谢了!
- access不能更新和插入
- 求AJAX实现只刷新datagrid的详细方法,谢谢大家
- 这个问题问了很久了帮忙解决一下吧!!难道没有人会吗??
- 一个小调查:请问大家一般用C#还是用VB.NET还是两样混合写ASP.NET呢?谢谢:)
- **=====XML 解析问题,解决即给分。等待===== **
{
string fullpath = @"http://www.baidu.com";
HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(fullpath);
HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
StreamReader strm = new StreamReader(webresp.GetResponseStream(), Encoding.Default);
string ret= strm.ReadToEnd();
MessageBox.Show (ret);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}