利用Cookie自动登录别人的网站
2010-02-26 16:59
429 查看
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
public partial class Default3 : System.Web.UI.Page
{
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CookieContainer cc = new CookieContainer();
string postData = "do=login&username=xiaoliu007&passwd=xiaoliu";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://info.sporttery.cn/lotterygame/index.php"));
webRequest2.CookieContainer = cc;
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();
cc.Add(response2.Cookies);
foreach (Cookie cookie in response2.Cookies) //将cookie设置为浏览的cookie
{
InternetSetCookie(
"http://" + cookie.Domain.ToString(),
cookie.Name.ToString(),
cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
System.Diagnostics.Process.Start("http://info.sporttery.cn/lotterygame/combination_num.php?s='234'&values=',001001,001002,001003,002001,002002,002003,003001,004001'&sports='fb'"); //打开浏览器
StreamReader sr2 = new StreamReader(response2.GetResponseStream(),Encoding.GetEncoding("gb2312"));
string text2 = sr2.ReadToEnd();
Response.Write(text2);
sr2.Close();
response2.Close();
//Console.WriteLine(outdata);
//再次显示"登录"
//如果把*行注释调,就显示"没有登录"
}
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
public partial class Default3 : System.Web.UI.Page
{
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CookieContainer cc = new CookieContainer();
string postData = "do=login&username=xiaoliu007&passwd=xiaoliu";
byte[] byteArray = Encoding.UTF8.GetBytes(postData); // 转化
HttpWebRequest webRequest2 = (HttpWebRequest)WebRequest.Create(new Uri("http://info.sporttery.cn/lotterygame/index.php"));
webRequest2.CookieContainer = cc;
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();
cc.Add(response2.Cookies);
foreach (Cookie cookie in response2.Cookies) //将cookie设置为浏览的cookie
{
InternetSetCookie(
"http://" + cookie.Domain.ToString(),
cookie.Name.ToString(),
cookie.Value.ToString() + ";expires=Sun,22-Feb-2099 00:00:00 GMT");
}
System.Diagnostics.Process.Start("http://info.sporttery.cn/lotterygame/combination_num.php?s='234'&values=',001001,001002,001003,002001,002002,002003,003001,004001'&sports='fb'"); //打开浏览器
StreamReader sr2 = new StreamReader(response2.GetResponseStream(),Encoding.GetEncoding("gb2312"));
string text2 = sr2.ReadToEnd();
Response.Write(text2);
sr2.Close();
response2.Close();
//Console.WriteLine(outdata);
//再次显示"登录"
//如果把*行注释调,就显示"没有登录"
}
}
}
相关文章推荐
- 【过滤器】(3)过滤器的应用案例:网站自动登录技术(Cookie记忆)
- python利用cookie登录网站进行访问
- Python 自动登录网站(处理Cookie)
- python+cookielib实现批量利用账号和密码自动获取新浪微博登录cookie
- 利用cookie自动登录
- 利用cookie实现自动登录
- Cookie-网站登录-下次自动登录
- Cookie-网站登录-下次自动登录2
- JAVA通过Session和Cookie实现网站自动登录的技术
- 利用Cookie进行自动登录相关代码
- servlet之利用cookie进行自动登录
- JSP 通过Session和Cookie实现网站自动登录
- php利用cookie实现自动登录的方法
- Python 自动登录网站(处理Cookie)
- [python 爬虫学习]利用cookie模拟网站登录
- Java利用Cookie实现自动登录
- python 利用selenium模拟登录帐号验证网站并获取cookie
- python模拟登录微博网站利用urllib2 和 cookie
- 解决通过Cookie进行网站自动登录的安全性问题
- php利用cookie自动登录方法