首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

200分求个小实例,如何自动登录网站

2012-06-08 
200分求个小实例,怎么自动登录网站http://topic.csdn.net/u/20100722/16/0968fa7a-1975-4767-a983-951809a

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?
[解决办法]
不用账号的话,,
怎么记录是谁登陆,又如何判断后台的操作权限;
这样的话不如点一下连接就直接经后台吧
[解决办法]

探讨
是WEB网站想要自动登录到其它网站,有地址账号密码

[解决办法]
用HttpWebRequest,先将用户名和密码发给服务器,将服务器返回的信息保存在cookie上,再登陆服务器就可以了。
[解决办法]
最近也写过一个测试的工具 用的winfrom做的 自动登录网站 测试Http响应时间 页面加载时间
 账户密码写到XML 里面在 URL地址需输入 用了个timer 自动登录
HttpWebReques HttpWebResponse

 前提是得知道URl地址的拼接 把账户密码 直接拼接到URL里面 就可以自动登录

[解决办法]
这个功能应该不难实现吧。
看一下,网站都需要提交什么数据,就照着样子提交就可以了。
[解决办法]
模拟登陆, 通过截获和模拟HTTP请求来实现!
[解决办法]
给你顶!~~~~~~~~~~~~~~
[解决办法]
用webbrowser控件
 System.Windows.Forms.HtmlDocument HTMLDocument = wbHistorySearch.Document;
System.Windows.Forms.HtmlElement loginName= HTMLDocument.GetElementById("loginName");
loginName.InnerText = System.Configuration.ConfigurationSettings.AppSettings["LoginName"].ToString();
//loginName.Enabled = false;
System.Windows.Forms.HtmlElement password = HTMLDocument.GetElementById("passwd");
password.InnerText = System.Configuration.ConfigurationSettings.AppSettings["Password"].ToString();
//password.Enabled = false;
System.Windows.Forms.HtmlElement btnLogin = HTMLDocument.GetElementById("login");
btnLogin.InvokeMember("click");
btnLogin.Enabled = false;
System.Windows.Forms.HtmlElement btnReset = HTMLDocument.GetElementById("Submit2");
btnReset.Enabled = false;
[解决办法]
当点击链接或按钮时 从后台取得账号和密码,然后跳转到相应的页面(在跳转的路径中包含账号和密码这两个信息)
[解决办法]
C# code
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控件,指向你的网站,然后在其中模拟登陆
第二种方法 模拟浏览器发送数据包,你可以先截取正确登陆的数据包,再模拟一个一样的发过去,也行
[解决办法]
该结贴了。。。
[解决办法]

探讨
引用:
是WEB网站想要自动登录到其它网站,有地址账号密码


有地址,帐号,密码

感觉有点像我最近和同事说的一个事情,她喜欢逛一个带有积分的网站。但是每天早上7点必须签到。才有积分,不然就扣积分。每天早上看她7点就起来,打开电脑,点击网站。登录进去//于是就想搞个自动开机,自动打开网址,自动登录进去。然后自己关机。哈哈。。。。

于是我……

[解决办法]
不知道,不是高手

热点排行