怎样通过cookie打开网页? 根据已知用户名和密码用HttpWebRequest获得的CookieContainer后,怎么能做出效果相当于在网站上真正登陆一样,以便打开或跳转到需要登陆的网页进行浏览! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面是我取CookieContainer的方法...CookieContainer取出来了,也可以用HttpWebResponse取得登录后想要的数据,但是不能直接跳转进入网站. private string PostWebRequest() { CookieContainer cc = new CookieContainer(); string postData = "logintype=uid&u=xxxx&psw=xxxx&product=mail&%B5%C7%C2%BC=%B5%C7+%C2%BC"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create("http://mail.sina.com.cn/cgi-bin/login.php"); webRequest2.CookieContainer = cc; webRequest2.AllowAutoRedirect = true; webRequest2.Method = "POST"; webRequest2.ContentType = "application/x-www-form-urlencoded"; webRequest2.ContentLength = byteArray.Length; Stream newStream = webRequest2.GetRequestStream(); // Send the data. newStream.Write(byteArray, 0, byteArray.Length); //写入参数 newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse(); response2.Cookies = cc.GetCookies(webRequest2.RequestUri); string a = ""; foreach (Cookie i in webRequest2.CookieContainer.GetCookies(new Uri("http://mail.sina.com.cn/cgi-bin/login.php"))) { a += i.ToString() + ";"; } cc.Add(response2.Cookies); StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.GetEncoding("UTF-8")); string str = sr2.ReadToEnd(); return str; } 把26个字母图片排列在一起并且每个都有点击事件 C#来源 ASP.net插入字符串! 启动任意程序问题,求教高手。。。 在C#中要关闭winform的时候我想让它弹出一个对话框!请问如何解决?急!!!大虾帮忙!! 帮忙看看。 再次触发事件,不在打开一进程?? 求问非UI线程修改UI的标准方法 高分求条码打印控件 关于接口 正则表达式过滤html中的脚本与样式 GroupBox 事件
private string PostWebRequest()
{
CookieContainer cc = new CookieContainer();
string postData = "logintype=uid&u=xxxx&psw=xxxx&product=mail&%B5%C7%C2%BC=%B5%C7+%C2%BC";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化 HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create("http://mail.sina.com.cn/cgi-bin/login.php");
webRequest2.CookieContainer = cc;
webRequest2.AllowAutoRedirect = true;
webRequest2.Method = "POST";
webRequest2.ContentType = "application/x-www-form-urlencoded";
webRequest2.ContentLength = byteArray.Length;
Stream newStream = webRequest2.GetRequestStream();
// Send the data.
newStream.Write(byteArray, 0, byteArray.Length); //写入参数
newStream.Close(); HttpWebResponse response2 = (HttpWebResponse)webRequest2.GetResponse();
response2.Cookies = cc.GetCookies(webRequest2.RequestUri);
string a = "";
foreach (Cookie i in webRequest2.CookieContainer.GetCookies(new Uri("http://mail.sina.com.cn/cgi-bin/login.php")))
{
a += i.ToString() + ";";
}
cc.Add(response2.Cookies);
StreamReader sr2 = new StreamReader(response2.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
string str = sr2.ReadToEnd();
return str;
}