C# 模拟用户登录
2014-02-21 11:51
239 查看
public static CookieContainer Get_Login()
{
CookieContainer cc = new CookieContainer();
string FormURL=http://www.fy681.com/login.aspx; //处理表单的绝对URL地址
string FormData = "username=dahai163&passwd=123"; //表单需要提交的参数,注意改为你已注册的信息。
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(FormData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormURL);
request.Method = "POST"; //数据提交方式
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
//模拟一个UserAgent
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
request.CookieContainer = cc;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cc.Add(response.Cookies);
Stream stream = response.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
return cc;
}
{
CookieContainer cc = new CookieContainer();
string FormURL=http://www.fy681.com/login.aspx; //处理表单的绝对URL地址
string FormData = "username=dahai163&passwd=123"; //表单需要提交的参数,注意改为你已注册的信息。
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(FormData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FormURL);
request.Method = "POST"; //数据提交方式
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
//模拟一个UserAgent
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
request.CookieContainer = cc;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cc.Add(response.Cookies);
Stream stream = response.GetResponseStream();
string WebContent = new StreamReader(stream, System.Text.Encoding.Default).ReadToEnd();
return cc;
}
相关文章推荐
- C#使用HttpWebRequest与HttpWebResponse模拟用户登录
- C#简单模拟用户登录类
- C#简单模拟用户登录类
- C#模拟网站用户登录
- 写了一个Windows服务,通过C#模拟网站用户登录并爬取BUG列表查询有没有新的BUG,并提醒我
- c# 实现网页上用户自动登陆|asp.net 模拟网站登录
- C#使用HttpWebRequest与HttpWebResponse模拟用户登录
- c# 实现网页上用户自动登陆|asp.net 模拟网站登录
- C#模拟网站用户登录(有意思)
- C#简单模拟用户登录类
- c# 模拟用户登录
- 用户模拟登录注册
- c# 一个托盘程序的详细设计过程(用户登录)
- C#项目中使用 Selenium + PhantomJS 模拟登录博客园
- C# ,webBrowser,登录,数据填充,模拟点击链接,运行JS
- Java HttpServlet模拟用户登录
- C#模拟POST登录cnblogs并发布文章
- Java小程序之集合框架模拟数据库实现用户登录和注册功能
- C# winform 窗体接收命令行参数自动登录进行系统,模拟600个WCF客户端的并发压力测试
- Python模拟用户登录验证