- 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://CodeSnippet.cn/");
- wc.Headers.Add("Origin", "http://CodeSnippet.cn");
- var bytes = wc.UploadValues("http://CodeSnippet.cn/", nvc);
- string responseHtml = Encoding.UTF8.GetString(bytes);
- //看responseHtml是否是登录后的结果
- String cookie = wc.ResponseHeaders[HttpResponseHeader.SetCookie];
- //如果登录成功可以使用此cookie继续执行其他操作
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/290920136247.html
来源: http://www.codesnippet.cn/detail/290920136247.html