200分求个小实例,怎么自动登录网站
http://topic.csdn.net/u/20100722/16/0968fa7a-1975-4767-a983-951809a69360.html?seed=236868321&r=67224612#r_67224612
一样的问题,可是给沉了,
给个例子好吧大侠们,网上的例子运行不动啊,
我有一个网站台后,
有账号密码,不要验证码,
我想弄一个链接按钮什么的,点一下就自动登录上。不用输账号密码
[解决办法]
up...
[解决办法]
webbrwower
htpwebrequest
http://topic.csdn.net/u/20100604/18/fadb1e99-e010-4aad-9e4f-bf5f0f745ee1.html
[解决办法]
给你顶
[解决办法]
顶起 Mark上
[解决办法]
http://topic.csdn.net/u/20090810/11/1d193df9-f3fb-487e-98ee-91bf7b5a9bf8.html
[解决办法]
或者说你的是WebForm?
[解决办法]
不用账号的话,,
怎么记录是谁登陆,又如何判断后台的操作权限;
这样的话不如点一下连接就直接经后台吧
[解决办法]
using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;namespace TestLoginWin.AppCode{ /// <summary> /// 访问WEB页面 /// </summary> /// <author>Jailu</author> /// <date>May 10, 2008</date> public class HttpHelper { #region 私有变量 private CookieContainer cc; private string contentType = "application/x-www-form-urlencoded"; private string accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; private string userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; #endregion #region 属性 public CookieContainer CookieContainer { get { return cc; } } #endregion #region 构造函数 public HttpHelper() { cc = new CookieContainer(); } public HttpHelper(CookieContainer cc) { this.cc = cc; } public HttpHelper(string contentType, string accept, string userAgent) { this.contentType = contentType; this.accept = accept; this.userAgent = userAgent; } public HttpHelper(CookieContainer cc, string contentType, string accept, string userAgent) { this.cc = cc; this.contentType = contentType; this.accept = accept; this.userAgent = userAgent; } #endregion #region 公共方法 public string GetHtml(string url, string postData, Method method, out CookieCollection cookieCollection) { if (string.IsNullOrEmpty(postData)) { return GetHtml(url, out cookieCollection); } byte[] byteRequest = Encoding.Default.GetBytes(postData); HttpWebRequest httpWebRequest; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpWebRequest.CookieContainer = cc; httpWebRequest.ContentType = contentType; httpWebRequest.Referer = url; httpWebRequest.Accept = accept; httpWebRequest.UserAgent = userAgent; httpWebRequest.Method = method == Method.POST ? "POST" : "GET"; httpWebRequest.ContentLength = byteRequest.Length; Stream stream = httpWebRequest.GetRequestStream(); stream.Write(byteRequest, 0, byteRequest.Length); stream.Close(); HttpWebResponse httpWebResponse; httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8); string html = streamReader.ReadToEnd(); streamReader.Close(); responseStream.Close(); cookieCollection = cc.GetCookies(new Uri(url)); return html; } public string GetHtml(string url, out CookieCollection cookieCollection) { HttpWebRequest httpWebRequest; httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); httpWebRequest.CookieContainer = cc; HttpWebResponse httpWebResponse; httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8); string html = streamReader.ReadToEnd(); streamReader.Close(); responseStream.Close(); cookieCollection = cc.GetCookies(new Uri(url)); return html; } public string GetHtml(string url) { CookieCollection cookieCollection; return GetHtml(url, out cookieCollection); } public string GetHtml(string url, string postData, Method method) { CookieCollection cookieCollection; return GetHtml(url, postData, method, out cookieCollection); } #endregion }}
[解决办法]
看你要登录什么网站了;
有session控制的用session
有cookies控制的用cookies了
服务器端设置的就没法登陆了
没有控制的就直接登录了
[解决办法]
点击时先连接到一个中间页面,在中间页面的load里拼URL并带上你的用户和密码
[解决办法]
总结上述几位答案
第一种方法 建一个webbrowser控件,指向你的网站,然后在其中模拟登陆
第二种方法 模拟浏览器发送数据包,你可以先截取正确登陆的数据包,再模拟一个一样的发过去,也行
[解决办法]
该结贴了。。。
[解决办法]