//执行登陆操作 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 ";//请求登录的URL try { CookieContainer cc = new CookieContainer();//接收缓存 byte[] byteArray = Encoding.UTF8.GetBytes(padata); // 转化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(url); //新建一个WebRequest对象用来请求或者响应url webRequest2.CookieContainer = cc; //保存cookie webRequest2.Method = "POST"; //请求方式是POST webRequest2.ContentType = "application/x-www-form-urlencoded"; //请求的内容格式为application/x-www-form-urlencoded webRequest2.ContentLength = byteArray.Length; Stream newStream = webRequest2.GetRequestStream(); //返回用于将数据写入 Internet 资源的 Stream。 // Send the data. newStream.Write(byteArray, 0, byteArray.Length); //写入参数 newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse(); StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.Default); string text2 = sr2.ReadToEnd(); |
|