小偷程序(ASP.NET+c#)

在.Net 平臺下,創建一個ASP.Net的程序
1、引用兩個NAMESPACE
      using System.Text     //因爲用了Encoding類
      using System.Net      //因爲用了WebClient 類
2、整個程序用了三個控件
      txtUrl    //輸入你要獲取的網頁地址 TEXTBOX控件
      txtBody  //得到你要獲取的網頁內容 TEXTBOX控件
      btnReturn  //按鈕BUTTON控件
3、在***.aspx.cs下的代碼
private void btnReturn_Click(object sender, System.EventArgs e)
  {
    string url=txtUrl.Text.Trim();    //獲取輸入的網頁地址

    WebClient wb=new WebClient();  //創建一個WebClient實例
    //獲取或設置用於對向 Internet 資源的請求進行身份驗證的網絡憑據。(可有可無)
    //wb.Credentials=CredentialCache.DefaultCredentials; 
    //從資源下載數據並返回字節數組。(加@是因爲網址中間有"/"符號)
    byte[] pagedata=wb.DownloadData(@url);
     //轉換字符、
    string result=Encoding.Default.GetString(pagedata);

    txtBody.Text=result; 
  }
4、字***.aspx的HTML代碼中加入一條代碼
     在第一行代碼<%@ page=.............................%> 中加入validateRequest=false
總結:整個代碼不過才幾行,而且還不用操心亂碼的事情,我是昨天自己在幫助文檔裏偶然看見的,其實WebClient類有很多下載資源和上載資源的方法,有興趣的朋友可以看看下面有關WebClient類的幫助文檔:
WebClient 類請參見
WebClient 成員 | System.Net 命名空間 | WebRequest | WebResponse | HttpWebRequest | 
HttpWebResponse | WebClient 成員(Visual J# 語法) | C++ 託管擴展編程 
要求
命名空間: System.Net
平臺: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP 
Professional, Windows Server 2003 系列
程序集: System (在 System.dll 中)
.NET Framework 安全性:  
WebPermission,用於訪問所請求的 URI 或請求被重定向到的任何 URI。關聯的枚舉:Connect。 
語言
C#
C++
JScript
Visual Basic
全部顯示
提供向 URI 標識的資源發送數據和從 URI 標識的資源接收數據的公共方法。不能繼承此類。
有關此類型所有成員的列表,請參閱 WebClient 成員。
System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Net.WebClient
[Visual Basic]
<ComVisible(True)>
NotInheritable Public Class WebClient
   Inherits Component
[C#]
[ComVisible(true)]
public sealed class WebClient : Component
[C++]
[ComVisible(true)]
public __gc __sealed class WebClient : public Component
[JScript]
public
   ComVisible(true)
class WebClient extends Component
線程安全
此類型的所有公共靜態(Visual Basic 中爲 Shared)成員對多線程操作而言都是安全的。但不保證任何實例
成員是線程安全的。
備註
WebClient 類提供向 URI 標識的任何本地、Intranet 或 Internet 資源發送數據以及從這些資源接收數據的
公共方法。
WebClient 類使用 WebRequest 類提供對 Internet 資源的訪問。WebClient 實例可以通過任何已向 
WebRequest.RegisterPrefix 方法註冊的 WebRequest 子代訪問數據。
注意   默認情況下,.NET Framework 支持以 http:、https: 和 file: 方案標識符開頭的 URI。
WebClient 類提供四種將數據上載到資源的方法: 
OpenWrite 返回一個用於將數據發送到資源的 Stream。 
UploadData 將字節數組發送到資源並返回包含任何響應的字節數組。 
UploadFile 將本地文件發送到資源並返回包含任何響應的字節數組。 
UploadValues 將 NameValueCollection 發送到資源並返回包含任何響應的字節數組。 
WebClient 類還提供三種從資源下載數據的方法: 
DownloadData 從資源下載數據並返回字節數組。 
DownloadFile 從資源將數據下載到本地文件。 
OpenRead 從資源以 Stream 的形式返回數據。 
要求
命名空間: System.Net
平臺: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP 
Professional, Windows Server 2003 系列
程序集: System (在 System.dll 中)
.NET Framework 安全性:  
WebPermission,用於訪問所請求的 URI 或請求被重定向到的任何 URI。關聯的枚舉:Connect。 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章