日期:2014-05-17 浏览次数:20816 次
public static CookieContainer CookieContainers = new CookieContainer();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string username = textBox2.Text.Trim();
string password = textBox3.Text.Trim();
string code = textBox4.Text.Trim();
string data="__VIEWSTATE=dDwtMTg3MTM5OTI5MTs7PhMbjAbINgvvHsvy%2FQdjcw3RMlRn&TextBox1="+username+"&TextBox2="+password+"&TextBox3="+code+"&RadioButtonList1=%D1%A7%C9%FA&Button1=&lbLanguage=";
string loginurl = "http://xk4.suda.edu.cn/";
getresponse(loginurl,data);
}
private void getresponse(string loginurl,string data)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(loginurl);
req.KeepAlive = true;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.UserAgent = "User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
req.Accept = "Accept text/html, application/xhtml+xml, */*";
req.Timeout = 50000;
req.AllowAutoRedirect = true;
req.CookieContainer = CookieContainers;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postBytes = encoding.GetBytes(data);
req.ContentLength = postBytes.Length;
Stream st = req.GetRequestStream();
st.Write(postBytes, 0, postBytes.Length);
st.Close();