獲取遠(yuǎn)程網(wǎng)頁(yè)的內(nèi)容之一(downmoon原創(chuàng))
更新時(shí)間:2007年03月06日 00:00:00 作者:
獲取遠(yuǎn)程網(wǎng)頁(yè)的內(nèi)容之一(downmoon原創(chuàng))
一、本機(jī)直接上網(wǎng)時(shí):
獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容#region 獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容
/**//// <summary>
/// 獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容
/// </summary>
/// <param name="strUrl">所要查找的遠(yuǎn)程網(wǎng)頁(yè)地址</param>
/// <param name="timeout">超時(shí)時(shí)長(zhǎng)設(shè)置,一般設(shè)置為8000</param>
/// <param name="enterType">是否輸出換行符,0不輸出,1輸出文本框換行</param>
/// <param name="EnCodeType">編碼方式</param>
/// <returns></returns>
/// 也可考慮 static string
public string GetRequestString(string strUrl,int timeout,int enterType,Encoding EnCodeType)
...{
string strResult;
try
...{
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl) ;
myReq.Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;
StreamReader sr = new StreamReader(myStream , EnCodeType);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
...{
strBuilder.Append(sr.ReadLine());
if(enterType==1)
...{
strBuilder.Append(" ");
}
}
strResult = strBuilder.ToString();
}
catch(Exception err)
...{
strResult = "請(qǐng)求錯(cuò)誤:" + err.Message;
}
return strResult ;
}
#endregion
二:通過(guò)域環(huán)境代理上網(wǎng)時(shí)這樣就不行了! 下篇文章分解,呵呵
一、本機(jī)直接上網(wǎng)時(shí):
獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容#region 獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容
復(fù)制代碼 代碼如下:
/**//// <summary>
/// 獲取指定遠(yuǎn)程網(wǎng)頁(yè)內(nèi)容
/// </summary>
/// <param name="strUrl">所要查找的遠(yuǎn)程網(wǎng)頁(yè)地址</param>
/// <param name="timeout">超時(shí)時(shí)長(zhǎng)設(shè)置,一般設(shè)置為8000</param>
/// <param name="enterType">是否輸出換行符,0不輸出,1輸出文本框換行</param>
/// <param name="EnCodeType">編碼方式</param>
/// <returns></returns>
/// 也可考慮 static string
public string GetRequestString(string strUrl,int timeout,int enterType,Encoding EnCodeType)
...{
string strResult;
try
...{
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl) ;
myReq.Timeout = timeout;
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream () ;
StreamReader sr = new StreamReader(myStream , EnCodeType);
StringBuilder strBuilder = new StringBuilder();
while (-1 != sr.Peek())
...{
strBuilder.Append(sr.ReadLine());
if(enterType==1)
...{
strBuilder.Append(" ");
}
}
strResult = strBuilder.ToString();
}
catch(Exception err)
...{
strResult = "請(qǐng)求錯(cuò)誤:" + err.Message;
}
return strResult ;
}
#endregion
相關(guān)文章
C# XML操作 代碼大全(讀XML,寫(xiě)XML,更新,刪除節(jié)點(diǎn),與dataset結(jié)合等)
C#操作XML(讀XML,寫(xiě)XML,更新,刪除節(jié)點(diǎn),與dataset結(jié)合等),以下就是操作XML的所有方法,相信可以滿(mǎn)足很大一部份的使用了。2009-06-06
aspx中的mysql操作類(lèi)sqldatasource使用示例分享
服務(wù)器裝了mysql odbc驅(qū)動(dòng),想在那個(gè)iis上操作另一個(gè)服務(wù)器的mysql,找到個(gè).net的sqldatasource類(lèi)可以操作mysql,下在把使用方法分享一下2014-01-01
ASP.NET筆記之 Request 、Response 與Server的使用
本篇文章小編為大家介紹,ASP.NET筆記之 Request 、Response 與Server的使用。需要的朋友參考下2013-04-04
ASP.NET中內(nèi)嵌頁(yè)面代碼的一個(gè)問(wèn)題
如果頁(yè)面繼承了一個(gè)父頁(yè)面,而且當(dāng)前頁(yè)面用new覆蓋了父頁(yè)面的某個(gè)屬性2010-02-02
Asp.net操作Excel更輕松的實(shí)現(xiàn)代碼
今天先介紹一個(gè)關(guān)于導(dǎo)出數(shù)據(jù)的例子,以Excel為模板。直接進(jìn)入正題了2011-10-10
asp.net Repeater 數(shù)據(jù)綁定的具體實(shí)現(xiàn)(圖文詳解)
此例子綁定的數(shù)據(jù)源為微軟在mssql2000中提供的Northwind數(shù)據(jù)庫(kù)中的表Categories。2013-07-07
ASP.NET中操作數(shù)據(jù)庫(kù)的基本步驟分享
ASP.NET中操作數(shù)據(jù)庫(kù)的基本步驟分享,學(xué)習(xí)asp.net的朋友可以參考下。2011-10-10

