asp.net中獲取遠程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))
更新時間:2007年04月02日 00:00:00 作者:
獲取遠程網(wǎng)頁的內(nèi)容之一(downmoon原創(chuàng))
一、本機直接上網(wǎng)時:
獲取指定遠程網(wǎng)頁內(nèi)容#region 獲取指定遠程網(wǎng)頁內(nèi)容
/**//// <summary>
/// 獲取指定遠程網(wǎng)頁內(nèi)容
/// </summary>
/// <param name="strUrl">所要查找的遠程網(wǎng)頁地址</param>
/// <param name="timeout">超時時長設(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 = "請求錯誤:" + err.Message;
}
return strResult ;
}
#endregion
二:通過域環(huán)境代理上網(wǎng)時這樣就不行了! 下篇文章分解,呵呵!
一、本機直接上網(wǎng)時:
獲取指定遠程網(wǎng)頁內(nèi)容#region 獲取指定遠程網(wǎng)頁內(nèi)容
復(fù)制代碼 代碼如下:
/**//// <summary>
/// 獲取指定遠程網(wǎng)頁內(nèi)容
/// </summary>
/// <param name="strUrl">所要查找的遠程網(wǎng)頁地址</param>
/// <param name="timeout">超時時長設(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 = "請求錯誤:" + err.Message;
}
return strResult ;
}
#endregion
二:通過域環(huán)境代理上網(wǎng)時這樣就不行了! 下篇文章分解,呵呵!
您可能感興趣的文章:
- asp.net下獲取遠程網(wǎng)頁的內(nèi)容之二(downmoon原創(chuàng))
- asp.net 網(wǎng)頁編碼自動識別代碼
- asp.net HttpWebRequest自動識別網(wǎng)頁編碼
- asp.net(c#)做一個網(wǎng)頁數(shù)據(jù)采集工具
- HttpWebRequest和HttpWebResponse用法小結(jié)
- ASP.NET MVC中解析淘寶網(wǎng)頁出現(xiàn)亂碼問題的解決方法
- asp.net 抓取網(wǎng)頁源碼三種實現(xiàn)方法
- C#中HttpWebRequest的用法詳解
- ASP.NET抓取網(wǎng)頁內(nèi)容的實現(xiàn)方法
- ASP.NET使用HttpWebRequest讀取遠程網(wǎng)頁源代碼
相關(guān)文章
MVC默認路由實現(xiàn)分頁(PagerExtend.dll下載)
這篇文章主要介紹了MVC默認路由實現(xiàn)分頁,采用bootstrap的樣式,文末提供了PagerExtend.dll下載地址,感興趣的小伙伴們可以參考一下2016-07-07asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時出現(xiàn)亂碼
asp.net中在用ajax格式傳遞數(shù)據(jù)到aspx頁面時有時會出現(xiàn)亂碼,很是疑惑,不要走開接下來介紹解決方法,感興趣的朋友可以了解下2013-01-01asp.net下使用DbProviderFactories的數(shù)據(jù)庫操作類
項目開發(fā)中用到VB.NET開發(fā),參考網(wǎng)上的資料,自己寫了數(shù)據(jù)庫操作類。2010-06-06Silverlight融合ajax實現(xiàn)前后臺數(shù)據(jù)交互
兩年前Silverlight 還未起名,故事發(fā)生在WPF/E 的年代里。07年8月在中軟實習(xí)時,我承擔(dān)起了在. Net 中嵌入WPF/E 的任務(wù),目的是增強用戶體驗。2009-05-05使用UserControl做網(wǎng)站導(dǎo)航條的思路 分析
使用UserControl做網(wǎng)站導(dǎo)航條的思路 分析...2007-09-09asp.net core 集成swagger ui的原理解析
本文主要講解了如何對API進行分組,這里僅僅是舉了一個按照API功能進行分組的例子,其實在實際開發(fā)中,要按照何種方式分組,可以按照需求靈活定義,比如按照API版本進行分組2021-10-10