| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 7279 人关注过本帖
标题:winform跳转到制定的网页并自动实现登陆功能
只看楼主 加入收藏
Sephirose
Rank: 1
来 自:四川-乐山
等 级:新手上路
帖 子:51
专家分:0
注 册:2013-3-26
结帖率:55.56%
收藏
 问题点数:0 回复次数:8 
winform跳转到制定的网页并自动实现登陆功能
作一个小项目,包含WEB端和客户端,web端已经完成,现在做客户端,想实现的功能是,客户端登录后,界面里有链接按钮,点击后会链接到WEB端的对应功能页面,就像QQ客户端,点击空间图标后,会自动链接到网上的QQ空间中,并完成登录,这个功能该怎么写啊,不知道如何入手,求大神给个思路,谢谢!
搜索更多相关主题的帖子: 小项目 客户端 网页 空间 如何 
2014-02-17 14:23
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
cs端打开网页呗  放个控件linkLabel然后设置text为要访问的网址 试试

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2014-02-18 08:32
Sephirose
Rank: 1
来 自:四川-乐山
等 级:新手上路
帖 子:51
专家分:0
注 册:2013-3-26
收藏
得分:0 
回复 2楼 wangnannan
WEB端是每个用户的权限和信息不一样,它们的界面显示的内容是不一样的,试过这种方法,链接过去页面上什么都没有,所以想实现的是从客户端链接到WEB端的时候,自动完成WEB端登录这一步,然后直接转到当初设定好的页面
2014-02-18 09:52
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
哦 这种啊 那得先post内容 给你点干货自己看看吧
程序代码:
using System;
using System.Collections.Generic;
using System.Text;
using using namespace Czt.Web
{
    /// <summary>
    /// 实现网站登录类
    /// </summary>
    public class Post
    {
        /// <summary>
        /// 网站Cookies
        /// </summary>
        private string _cookieHeader = string.Empty;
        public string CookieHeader
        {
            get
            {
                return _cookieHeader;
            }
            set
            {
                _cookieHeader = value;
            }
        }
        /// <summary>
        /// 网站编码
        /// </summary>
        private string _code = string.Empty;
        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }


        private string _pageContent = string.Empty;
        public string PageContent
        {
            get { return _pageContent; }
            set { _pageContent = value; }
        }

        private Dictionary<string, string> _para = new Dictionary<string, string>();
        public Dictionary<string, string> Para
        {
            get { return _para; }
            set { _para = value; }
        }


        /**/
        /// <summary>
        /// 功能描述:模拟登录页面,提交登录数据进行登录,并记录Header中的cookie
        /// </summary>
        /// <param name="strURL">登录数据提交的页面地址</param>
        /// <param name="strArgs">用户登录数据</param>
        /// <param name="strReferer">引用地址</param>
        /// <param name="code">网站编码</param>
        /// <returns>可以返回页面内容或不返回</returns>
        public string PostData(string strURL, string strArgs, string strReferer, string code, string method)
        {
            return  PostData(strURL,  strArgs,  strReferer,  code,  method, string.Empty);
        }
        public string PostData(string strURL, string strArgs, string strReferer, string code, string method, string contentType)
        {
            try
            {
                string strResult = "";
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
                myHttpWebRequest.AllowAutoRedirect = true;
                myHttpWebRequest.KeepAlive = true;
                myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
                myHttpWebRequest.Referer = strReferer;


                myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";

                if (string.IsNullOrEmpty(contentType))
                {
                    myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                }
                else
                {
                    myHttpWebRequest.ContentType = "contentType";
                }

                myHttpWebRequest.Method = method;

                myHttpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

                if (myHttpWebRequest.CookieContainer == null)
                {
                    myHttpWebRequest.CookieContainer = new CookieContainer();
                }

                if (this.CookieHeader.Length > 0)
                {
                    myHttpWebRequest.Headers.Add("cookie:" + this.CookieHeader);
                    myHttpWebRequest.CookieContainer.SetCookies(new Uri(strURL), this.CookieHeader);
                }


 

                byte[] postData = Encoding.GetEncoding(code).GetBytes(strArgs);
                myHttpWebRequest.ContentLength = postData.Length;

                 PostStream = myHttpWebRequest.GetRequestStream();
                PostStream.Write(postData, 0, postData.Length);
                PostStream.Close();

                HttpWebResponse response = null;
                 sr = null;
                response = (HttpWebResponse)myHttpWebRequest.GetResponse();


 

                if (myHttpWebRequest.CookieContainer != null)
                {
                    this.CookieHeader = myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));
                }

                sr = new (response.GetResponseStream(), Encoding.GetEncoding(code));    //    //utf-8
                strResult = sr.ReadToEnd();
                sr.Close();
                response.Close();
                return strResult;
            }
            catch (Exception ex)
            {
                Utilities.Document.Create("C:\\error.log", strArgs, true, Encoding.UTF8);
            }
            return string.Empty;
        }

        /**/
        /// <summary>
        /// 功能描述:在PostLogin成功登录后记录下Headers中的cookie,然后获取此网站上其他页面的内容
        /// </summary>
        /// <param name="strURL">获取网站的某页面的地址</param>
        /// <param name="strReferer">引用的地址</param>
        /// <returns>返回页面内容</returns>
        public string GetPage(string strURL, string strReferer, string code)
        {
            return GetPage(strURL, strReferer,code,string.Empty);
        }
        public string GetPage(string strURL, string strReferer,string code,string contentType)
        {
            string strResult = "";
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
            myHttpWebRequest.AllowAutoRedirect = true;
            myHttpWebRequest.KeepAlive = false;
            myHttpWebRequest.Accept = "*/*";
            myHttpWebRequest.Referer = strReferer;
            myHttpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

            myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
            if (string.IsNullOrEmpty(contentType))
            {
                myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
            }
            else
            {
                myHttpWebRequest.ContentType = contentType;
            }
            myHttpWebRequest.Method = "GET";

            if (myHttpWebRequest.CookieContainer == null)
            {
                myHttpWebRequest.CookieContainer = new CookieContainer();
            }

            if (this.CookieHeader.Length > 0)
            {
                myHttpWebRequest.Headers.Add("cookie:" + this.CookieHeader);
                myHttpWebRequest.CookieContainer.SetCookies(new Uri(strURL), this.CookieHeader);
            }


            HttpWebResponse response = null;
             sr = null;
            response = (HttpWebResponse)myHttpWebRequest.GetResponse();


            Stream streamReceive;
            string gzip = response.ContentEncoding;

            if (string.IsNullOrEmpty(gzip) || gzip.ToLower() != "gzip")
            {
                streamReceive = response.GetResponseStream();
            }
            else
            {
                streamReceive = new (response.GetResponseStream(), );
            }

            sr = new (streamReceive, Encoding.GetEncoding(code));

            if (response.ContentLength > 1)
            {
                strResult = sr.ReadToEnd();
            }
            else
            {
                char[] buffer=new char[256];
                int count = 0;
                StringBuilder sb = new StringBuilder();
                while ((count = sr.Read(buffer, 0, buffer.Length)) > 0)
                {
                    sb.Append(new string(buffer));
                }
                strResult = sb.ToString();
            }
            sr.Close();
            response.Close();
            return strResult;
        }

    }
}

 

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2014-02-18 10:12
wangnannan
Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18
等 级:贵宾
威 望:87
帖 子:2546
专家分:9359
注 册:2007-11-3
收藏
得分:0 
先post数据 然后访问页面登录

出来混,谁不都要拼命的嘛。 。拼不赢?那就看谁倒霉了。 。有机会也要看谁下手快,快的就能赢,慢。 。狗屎你都抢不到。 。还说什么拼命?
2014-02-18 10:18
shangsharon
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
威 望:7
帖 子:221
专家分:1261
注 册:2012-3-25
收藏
得分:0 
当你在客户端登录后,在服务器上记录一个惟一标识KeyID,然后在打开的登录链接里加入KeyID,登录页面中代码验证QueryString["KeyID"]的值和服务器保存的标识是否一致,QQ大致是这样的,可以多加几个标识信息,如ip地址,时间戳,客户端版本,客户端操作系统系统版本等加强验证.
PS:从QQ面板上打开空间时,如果将其打开的浏览器的地址复制,在其他电脑上也是可以直接登录QQ空间的,但是也有一定的ip范围限制,可能会出现QQ异地登录的问题(ip范围跨度太大了).可以试试哦.

[ 本帖最后由 shangsharon 于 2014-2-20 10:27 编辑 ]
2014-02-18 11:32
yinniannian
Rank: 9Rank: 9Rank: 9
来 自:河北省石家庄
等 级:蜘蛛侠
威 望:2
帖 子:256
专家分:1007
注 册:2011-5-13
收藏
得分:0 
学习了。

代做小型软件。
QQ:449795473
2014-02-19 10:06
做好每一天
Rank: 2
等 级:论坛游民
威 望:3
帖 子:25
专家分:37
注 册:2014-2-19
收藏
得分:0 
学习了。。
2014-02-20 11:59
livelwd
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-2-28
收藏
得分:0 
回复 楼主 Sephirose
请问最后是如何实现的
2016-12-09 15:00
快速回复:winform跳转到制定的网页并自动实现登陆功能
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027258 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved