//執(zhí)行登陸操作 public static bool ExecLogin(string name,string pass) { bool result = false; string password = GetMd5Str32(pass).ToUpper(); string padata = "username=" + name + "&pwd=" + password + "&imgcode=&f=json"; string url = "http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN ";//請(qǐng)求登錄的URL try { CookieContainer cc = new CookieContainer();//接收緩存 byte[] byteArray = Encoding.UTF8.GetBytes(padata); // 轉(zhuǎn)化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(url); //新建一個(gè)WebRequest對(duì)象用來請(qǐng)求或者響應(yīng)url webRequest2.CookieContainer = cc; //保存cookie webRequest2.Method = "POST"; //請(qǐng)求方式是POST webRequest2.ContentType = "application/x-www-form-urlencoded"; //請(qǐng)求的內(nèi)容格式為application/x-www-form-urlencoded webRequest2.ContentLength = byteArray.Length; Stream newStream = webRequest2.GetRequestStream(); //返回用于將數(shù)據(jù)寫入 Internet 資源的 Stream。 // Send the data. newStream.Write(byteArray, 0, byteArray.Length); //寫入?yún)?shù) newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse(); StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default); string text2 = sr2.ReadToEnd(); |
|