複製代碼 代碼如下:public static void Disconnect(){
string url = "斷 線";
string uri = "http://192.168.1.1/userRpm/StatusRpm.htm?Disconnect=" + System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.GetEncoding("gb2312")) + "&wan=1";
string sUser = "admin";
string sPwd = "admin";
string sDomain = "";
NetworkCredential oCredential;
HttpWebRequest oRequest = (System.Net.HttpWebRequest)WebRequest.Create(uri);
if (oRequest != null)
{
oRequest.ProtocolVersion = HttpVersion.Version11;// send request
oRequest.Method = "GET";
oRequest.ContentType = "application/x-www-form-urlencoded";
oRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB6.4; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
oRequest.Referer = "http://192.168.1.1";
if (sUser != String.Empty)
{
oCredential = new NetworkCredential(sUser, sPwd, sDomain);
oRequest.Credentials = oCredential.GetCredential(new Uri(uri), String.Empty);
}
else
{
oRequest.Credentials = CredentialCache.DefaultCredentials;
}
StreamReader sr = new StreamReader(oRequest.GetResponse().GetResponseStream(), System.Text.Encoding.Default);
string line = sr.ReadToEnd();
sr.Close();
if (line.IndexOf("LAN口狀態") > -1)//登入成功
{
Console.WriteLine("斷開登入成功");
}
else
{
Console.WriteLine("斷開登入失敗");
}
}
}