1. 程式人生 > >Winform模擬登陸網站

Winform模擬登陸網站

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);//根據地址建立個request物件
string data = "accountName=" +name+"&password=" + password";//引數s
request.CookieContainer = new CookieContainer();//建立Cookie
request.Method = "POST";//以Post方式提交
request.ContentType = "application/x-www-form-urlencoded";//設定網頁的型別
request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.366.2 Safari/533.4";
request.ContentLength = data.Length;
request.Timeout = 60 * 1000;//超時1分鐘
request.KeepAlive = false;