C# 路由器互动操作

//以D-Link DI-624+A为例:

private void postrequest()
{
string userName = "admin";
string password = "702";
CookieContainer webCookieContainer
= new CookieContainer();
String url
= "http://192.168.1.1";
HttpWebRequest req
= (HttpWebRequest)WebRequest.Create(url);
req.Method
= "GET";
req.UserAgent
= "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;CIBA)";
req.CookieContainer
= webCookieContainer;
req.KeepAlive
= true;
req.Accept
= "*/*";
req.PreAuthenticate
= true;
CredentialCache myCache
=new CredentialCache();
myCache.Add(
new Uri("http://192.168.1.1"), "Basic", new NetworkCredential(userName, password));//添加Basic认证
req.Credentials = myCache;
HttpWebResponse resp
= (HttpWebResponse)req.GetResponse();
resp.Cookies
= webCookieContainer.GetCookies(req.RequestUri);
StreamReader sr
= new StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default);
String line
= sr.ReadToEnd();//这里就是网页内容了。
sr.Close();
resp.Close();
}

你可能感兴趣的:(C++,c,windows,C#)