C#使用WebClient类来模拟登录表单
2018-07-20 来源:open-open
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections.Specialized;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
using (WebClient wc = new WebClient())
{
NameValueCollection nvc = new NameValueCollection();
nvc.Add("UserName", "xxx");
nvc.Add("PassWord", "495e5");
nvc.Add("Btn_Login.x", "19");
nvc.Add("Btn_Login.y", "0");
nvc.Add("challenge", "ddd");
nvc.Add("type", "1");
//添加必要的http请求头
wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 AlexaToolbar/alxg-3.1");
wc.Headers.Add(HttpRequestHeader.Referer, "http://outofmemory.cn/");
wc.Headers.Add("Origin", "http://outofmemory.cn");
var bytes = wc.UploadValues("http://outofmemory.cn/", nvc);
string responseHtml = Encoding.UTF8.GetString(bytes);
//看responseHtml是否是登录后的结果
String cookie = wc.ResponseHeaders[HttpResponseHeader.SetCookie];
//如果登录成功可以使用此cookie继续执行其他操作
}
}
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐