你的位置:首页 > ASP.net教程

[ASP.net教程]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         PostdataByte = Encoding.UTF8.GetBytes("[ACT_REBOOT#0,0,0,0,0,0#0,0,0,0,0,0]0,0\r\n"),19         //后面的\r\n不能少20         PostDataType = CsharpHttpHelper.Enum.PostDataType.Byte,21         //CsharpHttpHelper是HttpHelper的类库22         Cookie = "Authorization=Basic XXXXXXXXXXXXXX==",23         //Authorization=Basic Base64加密你的密码24 25       };26       HttpResult result = http.GetHtml(item);27       if (result.StatusCode == System.Net.HttpStatusCode.OK)28       {29         if (result.Html == "[error]0")30         {31           Console.WriteLine("路由器重启成功!");32         }33         else34         {35           Console.WriteLine(result.Html);36         }37       }38       Console.ReadKey();39     }40   }41 }


 

HttpHelper万能框架网址:http://httphelper.sufeinet.com/