110,533
社区成员
发帖
与我相关
我的任务
分享
string name = txt_name.Text;
string pwd = txt_pass.Text;
string url = txt_ip.Text;
CookieContainer cookie = new CookieContainer();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req = (HttpWebRequest)WebRequest.Create(url + "/advanced.htm?wifi_mode=2&wifi_ssid=MXCHIP_42524A&security_mode=2&wifi_key=&wifi_ssid1=dosoft&security_mode1=0&wifi_key1=&wifi_ssid2=&security_mode2=0&wifi_key2=&wifi_ssid3=&security_mode3=0&wifi_key3=&wifi_ssid4=&security_mode4=0&wifi_key4=&uap_ssid=&uap_secmode=1&uap_key=&socket_mode=0&dhcp_enalbe=0&local_ip_addr=192.168.1.1&netmask=255.255.255.0&gateway_ip_addr=192.168.1.1&dns_server=192.168.1.1&remote_server_mode=0&remote_dns=114.91.236.155&rport=8080&lport=8080&udp_enalbe=0&estype=4&esaddr=&esrport=0&eslport=0&baudrate=0&parity=0&data_length=0&stop_bits=0&cts_rts_enalbe=0&dma_buffer_size=0&uart_trans_mode=4&device_num=0&ps_enalbe=0&tx_power=31&keepalive_num=4&keepalive_time=120&socks_type=0&socks_addr=0.0.0.0&socks_port=0&socks_user=&socks_pass=&socks_1=0&socks_2=0&web_user=admin&web_pass=admin&device_name=EMW_3162+%2842524A%29&roam_val=75&udp_enable=0&save=Save");
req.Method = "POST";
req.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; qdesk 2.5.1269.201; Windows NT 6.1; Trident/5.0)";
req.CookieContainer = cookie;
req.KeepAlive = true;
req.Accept = "text/html, application/xhtml+xml, */*";
req.PreAuthenticate = true;
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(url), "Basic", new NetworkCredential(name, pwd));
req.Credentials = cache;
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
res.Cookies = cookie.GetCookies(req.RequestUri);
using (var io = new System.IO.StreamReader(res.GetResponseStream(), System.Text.Encoding.Default))
{
var str = io.ReadToEnd();
Console.WriteLine(str);
io.Close();
}
res.Close();
其中
req.PreAuthenticate = true;
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(url), "Basic", new NetworkCredential(name, pwd));
req.Credentials = cache;
是比较重要的代码了.也就是模拟弹出对话框那种登陆...