C#使用HttpHelper萬能框架,重啓路由器

首先聲明,不是全部路由器均可以經過下面的代碼來讓路由器執行重啓。框架

下面的代碼測試的路由器是(TP-LINK TD-W89841N加強型)。要根據本身的路由器來寫代碼。測試

 1 using CsharpHttpHelper; //引用HttpHelper類庫
 2 using System;
 3 using System.Text;
 4 
 5 namespace ConsoleApplication1
 6 {
 7     class Program
 8     {
 9         static void Main(string[] args)
10         {
11             HttpHelper http = new HttpHelper();
12             HttpItem item = new HttpItem()
13             {
14                 Referer = "http://192.168.1.1/",
15                 //這個不能少
16                 URL = "http://192.168.1.1/cgi?7",
17                 Method = "Post",
18                 Postdata = "[ACT_REBOOT#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n",
19                 //後面的\r\n不能少
20                 Cookie = "Authorization=Basic XXXXXXXXXXXXXXX==",
21                 //Authorization=Basic Base64加密你的密碼
22 
23             };
24             HttpResult result = http.GetHtml(item);
25             if (result.StatusCode == System.Net.HttpStatusCode.OK)
26             {
27                 if (result.Html == "[error]0")
28                 {
29                     Console.WriteLine("路由器重啓成功!");
30                 }
31                 else
32                 {
33                     Console.WriteLine(result.Html);
34                 }
35             }
36             Console.ReadKey();
37         }
38     }
39 }

HttpHelper萬能框架網址:http://httphelper.sufeinet.com/加密

相關文章
相關標籤/搜索