做过---模拟登录 请进 (winform)急。。。。。。

zhulong1111 2011-05-10 01:46:15
能否给点dome,谢谢 急。。。。。。
...全文
206 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
白云任去留 2011-05-12
  • 打赏
  • 举报
回复
httpWebRequest、Stream、CookieContainer...
zhulong1111 2011-05-12
  • 打赏
  • 举报
回复
非常感谢
sxldfang 2011-05-11
  • 打赏
  • 举报
回复
zhulong1111 2011-05-11
  • 打赏
  • 举报
回复
顺便问下 一半用什么工具分析web post提交的数据包? 带说明文档
zhulong1111 2011-05-11
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 net_lover 的回复:]
下面是一个例子

C# code
String login = "登录地址。也就是登录数据提交的URL";
String loginData = "登录表单信息";
HttpWebRequest req = WebRequest.Create(login) as HttpWebRequest;
req.Method = "POST";
req.AllowAutoRedirect = ……
[/Quote]非常感谢
子夜__ 2011-05-10
  • 打赏
  • 举报
回复
harderLi 2011-05-10
  • 打赏
  • 举报
回复
原理是post用户名和密码得到cookie值 用这个标识保持登录状态去取数据
harderLi 2011-05-10
  • 打赏
  • 举报
回复
class CelectCookie
{
public static CookieContainer ckr=new CookieContainer ();
public static CookieContainer getCookie()
{
CookieContainer Cookies = ckr;
string url = "http://www.yododo.com/user/login.ydd";
NameValueCollection nvc = new NameValueCollection();
nvc.Add("user.email","这里填写你的用户名");
nvc.Add("userpassword","你的密码");
string strpostData = "user.email=你的用户名&user.password=你的密码";
HttpWebRequest myRequest;
Stream newStream = null;
HttpWebResponse myResponse = null;
byte[] data = null;
if (!string.IsNullOrEmpty(strpostData))
data = Encoding.UTF8.GetBytes(strpostData);
myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Timeout = 100000;
if (data != null) myRequest.ContentLength = data.Length;
myRequest.UserAgent = "Baiduspider Disallow:/";
myRequest.Accept = "application/x-shockwave-flash,image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,application/x-silverlight,application/x-ms-application,application/x-ms-xbap,application/vnd.ms-xpsdocument,application/xaml+xml,*/*";
myRequest.AllowAutoRedirect = false;
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.CookieContainer = Cookies;
myRequest.Method = "POST";
newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
myResponse = (HttpWebResponse)myRequest.GetResponse();
ckr.Add(myResponse.Cookies);
newStream.Close();
return ckr;
}
public static void getContent()
{
string url = "要访问的网站";
ckr = getCookie();
HttpWebRequest myRequest = null;
Stream newStream = null;
HttpWebResponse myResponse = null;
myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Headers.Set("Pragma", "no-cache");
myRequest.Timeout = 100000;
myRequest.CookieContainer = ckr;
myRequest.Method = "GET";
myRequest.UserAgent = "Baiduspider Disallow:/";
myRequest.Accept = "application/x-shockwave-flash,image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/vnd.ms-excel,application/vnd.ms-powerpoint,application/msword,application/x-silverlight,application/x-ms-application,application/x-ms-xbap,application/vnd.ms-xpsdocument,application/xaml+xml,*/*";
myRequest.AllowAutoRedirect = false;
myRequest.ContentType = "application/x-www-form-urlencoded";
myResponse = (HttpWebResponse)myRequest.GetResponse();
System.IO.Stream streamReceive = myResponse.GetResponseStream();
System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader streamReader = new StreamReader(streamReceive, encoding);
string strResult = streamReader.ReadToEnd();
}
}
孟子E章 2011-05-10
  • 打赏
  • 举报
回复
下面是一个例子
String login = "登录地址。也就是登录数据提交的URL";
String loginData = "登录表单信息";
HttpWebRequest req = WebRequest.Create(login) as HttpWebRequest;
req.Method = "POST";
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
req.Referer = "http://www.xxxxxxxxxxxxxxxx.com/"; //自己看说设置,与login 里面的域名相同
byte[] byteArray = Encoding.GetEncoding("GB2312").GetBytes(loginData); //根据不同的网站选择不同的编码
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = byteArray.Length;
Stream newStream = req.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
newStream.Dispose();
CookieContainer container = new System.Net.CookieContainer();
req.CookieContainer = container;
HttpWebResponse res = req.GetResponse() as HttpWebResponse;
res.Cookies = container.GetCookies(req.RequestUri);
StreamReader sw = new StreamReader(res.GetResponseStream());
LoginResult.Text = sw.ReadToEnd(); //登录的返回信息,是否成功,里面的内容可以判断
sw.Close();



String topicUrl = "其他页面的URL。";

//title = System.Web.HttpUtility.UrlEncode(title, System.Text.UnicodeEncoding.GetEncoding("utf-8"));
String data = "另外页面的操作信息数据,如发贴";
req = HttpWebRequest.Create(topicUrl) as HttpWebRequest;
req.CookieContainer = container;
req.Method = "POST";
req.AllowAutoRedirect = true;
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.8,zh-hk;q=0.6,ja;q=0.4,zh;q=0.2");
req.Headers.Add("Accept-Encoding", "gzip,deflate");
req.Headers.Add("Accept-Charset", "GB2312,utf-8;q=0.7,*;q=0.7");
req.KeepAlive = true;
req.ContentType = "application/x-www-form-urlencoded";
req.Referer = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

byteArray = Encoding.GetEncoding("utf-8").GetBytes(data);
req.ContentLength = byteArray.Length;
newStream = req.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();

res = req.GetResponse() as HttpWebResponse;
sw = new StreamReader(res.GetResponseStream());
PubResult.Text = sw.ReadToEnd();//操作信息结果
sw.Close();
res.Close();
zhulong1111 2011-05-10
  • 打赏
  • 举报
回复
木有人帮下忙么?
zhulong1111 2011-05-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 myhope88 的回复:]
网上搜索下呗,应该挺多demo的吧
[/Quote]就是很多 看的很模糊 有没那个兄弟弄过嘛 指导下
myhope88 2011-05-10
  • 打赏
  • 举报
回复
网上搜索下呗,应该挺多demo的吧
zhulong1111 2011-05-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 youbl 的回复:]
用HttpWebRequest登录后,把HttpWebRequest.CookieContainer用到获取别的页面的CookieContainer,就可以使用登录后的信息了



引用 5 楼 zhulong1111 的回复:
引用 2 楼 net_lover 的回复:
winform?
还是
webform
>
winform 去模拟webform的登录
[/Quote]哥们 方便给个QQ么? 这问题比较急哈
游北亮 2011-05-10
  • 打赏
  • 举报
回复
用HttpWebRequest登录后,把HttpWebRequest.CookieContainer用到获取别的页面的CookieContainer,就可以使用登录后的信息了


[Quote=引用 5 楼 zhulong1111 的回复:]
引用 2 楼 net_lover 的回复:
winform?
还是
webform
>
winform 去模拟webform的登录
[/Quote]
-小蕾- 2011-05-10
  • 打赏
  • 举报
回复
什么模拟登录啊,什么样的?
日日新 2011-05-10
  • 打赏
  • 举报
回复
可能是木有人
zhulong1111 2011-05-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 net_lover 的回复:]
winform?
还是
webform
>
[/Quote]winform 去模拟webform的登录
游北亮 2011-05-10
  • 打赏
  • 举报
回复
需求都不清楚,
是winform模拟登录网站?
加载更多回复(3)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧