我们有几个不同的系统,每一个系统都有不同的用户名和密码,这样导致很多员工遗忘密码的情况发生,所以打算打一个一键登录的功能,我想的办法是,模拟写一个登录页面,代码简述如下.<html>
<head>
<script type="text/javascript">
myform.submit();
</script>
<body>
<form action="目标网站" name="myform" method="post">
<input type="hidden" value="123" name="loginname" />
<input type="hidden" value="456" name="password" />
</form>
</body>
</head>
</html>以上代码是通过模拟一个登录页面来实现了跳过登录界面进行登录.
在以上功能的基础上,我想实现通过一键登录进入系统后,继续实现页面的跳转,
例如:自动登进去以后,我想自动跳到http://目标网站/目标页面.
对以上功能的实现,没有任何想法,就试着在
myform.submit()下增加了window.location="http://目标网站//目标页面
增加了上述一句代码后,不仅没实现跳转功能,原来的一键登录也不能工作,系统只是简单的去了目标网站的登录的界面.
不知道各位有没有这种需求,以及是怎么实现的.希望可以提个醒.

解决方案 »

  1.   

    补充一句,目标网站是用jsp实现的.
      

  2.   

    可以模拟登录吧.
    给登录页post帐号和密码,获取响应的信息.如果响应的信息是登录成功标记则跳转到相应的页面
      

  3.   

    我感觉你这种方式是可行,怎么向登录页面post帐号和密码,我是刚学这个东西,我试了一下ajax方式,可发现不成功.
      

  4.   

    不用ajax,  StringBuilder sb = new StringBuilder();        sb.Append("name=1&");
            sb.Append("pwd=1");
     string vpcURL = "https://目标页面";
            System.Net.WebClient webClient = new System.Net.WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            byte[] response = webClient.UploadData(vpcURL, "POST", System.Text.Encoding.ASCII.GetBytes(sb.ToString()));
            string responseData = System.Text.Encoding.ASCII.GetString(response, 0, response.Length);在目标页面接收传来的参数
    try{
     foreach (string item in Page.Request.Form) {if (Page.Request.Form[item] != ""){}}
    }catch{}
      

  5.   

    用的6楼提供的方法,确实可以达到post提交form的数据格式,不过我这由于种种原因不能用.
    所以我又看了一个目标网站的源代码,发现它也是用post发送的提交,可我将他们的源代码贴到我
    的程序中,并不能像它那样post.   <script type="text/javascript">
            function GetPageSize() {
                var scrW, scrH;
                if (window.innerHeight && window.scrollMaxY) {
                    // Mozilla    
                    scrW = window.innerWidth + window.scrollMaxX;
                    scrH = window.innerHeight + window.scrollMaxY;
                } else if (document.body.scrollHeight > document.body.offsetHeight) {
                    // all but IE Mac    
                    scrW = document.body.scrollWidth;
                    scrH = document.body.scrollHeight;
                } else if (document.body) {
                    // IE Mac    
                    scrW = document.body.offsetWidth;
                    scrH = document.body.offsetHeight;
                }
                var winW, winH;
                if (window.innerHeight) {
                    // all except IE    
                    winW = window.innerWidth;
                    winH = window.innerHeight;
                } else if (document.documentElement && document.documentElement.clientHeight) {
                    // IE 6 Strict Mode    
                    winW = document.documentElement.clientWidth;
                    winH = document.documentElement.clientHeight;
                } else if (document.body) {
                    // other    
                    winW = document.body.clientWidth;
                    winH = document.body.clientHeight;
                }
                // for small pages with total size less then the viewport  
                var pageW = (scrW < winW) ? winW : scrW;
                var pageH = (scrH < winH) ? winH : scrH;
                return { PageW: pageW, PageH: pageH, WinW: winW, WinH: winH };
            }
            function setPageSize() {
                //处理浏览器窗口大小信息
                var winInfo = GetPageSize();
                //alert("pageW:"+winInfo.PageW+"pageH:"+winInfo.PageH+"winW:"+winInfo.WinW+"winH:"+winInfo.WinH);
                loginForm.clientWidthScreen.value = winInfo.WinW;
                loginForm.clientHeightScreen.value = winInfo.WinH;
                loginForm.pageWidthScreen.value = winInfo.PageW;
                loginForm.pageHeightScreen.value = winInfo.PageH;
                //alert(loginForm.clientWidthScreen.value);
            }
            function loginUser() {
                setPageSize(); //获取当前窗口大小进行保存            var url = "http://1.2.3.4/loginAction_loginUserForInterface.action";
                var loginname = "123";
                var userId = "";
                var password = "111";
                var fydm = "M53";
                var loginType = "1";
                var datas = {
                    loginname: loginname,
                    userId: userId,
                    password: password,
                    fydm: fydm
                }
                $.post(url, datas, function (data) {
                    if (data == 'true') {
                        
                       
                            location.href = "/view/sbxx/sbxxlist.jsp";
                     
            }        function searchfy() {
                var url = "/xtgl/gnqxgl/showtree.jsp?type=login";
                dialog("法院选择", "iframe:" + url, "350", "450", "iframe");
            }               $(document).ready(function () {
                loginUser();
            });
        </script>
    </head>
    <body>
        <form name="loginForm" action="" method="post">
        <input name="clientWidthScreen" type="hidden" value="1024" />
        <input name="clientHeightScreen" type="hidden" value="768" />
        <input name="pageWidthScreen" type="hidden" value="1024" />
        <input name="pageHeightScreen" type="hidden" value="768" />
        </form>
    </body>
    </html>
    <script type="text/javascript">
        $(document).ready(function () {
            //window.open("http://www.baidu.com");
            //window.open ('MessageBoard.jsp', 'MessageWindow', 'height=300, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no')
            setPageSize();
        });
        function setPageSize() {
            //处理浏览器窗口大小信息
            var winInfo = GetPageSize();
            //alert("pageW:"+winInfo.PageW+"pageH:"+winInfo.PageH+"winW:"+winInfo.WinW+"winH:"+winInfo.WinH);
            loginForm.clientWidthScreen.value = winInfo.WinW;
            loginForm.clientHeightScreen.value = winInfo.WinH;
            loginForm.pageWidthScreen.value = winInfo.PageW;
            loginForm.pageHeightScreen.value = winInfo.PageH;
            //alert(loginForm.clientWidthScreen.value);
        }
    </script>
    我用wireshark抓了一下包,发现在它的原网站post出去以后,数据和form用submit提交的一样,而我用相同代码执行,却发出去的包不一样.
    原网站发出的是:POST /loginAction_loginUserForInterface.action HTTP/1.1 (application/x-www.form-urlencoded)
    而我发出的是:OPTIONS /loginAction_loginUserForInterface.action HTTP/1.1
      

  6.   

    刚才我又查了一些资料,发现我的提交方式叫options方式,原网站的叫post方式,可我调用的是$.post()为什么会出现这种情况.
      

  7.   

    楼主,你想多了。
    我来帮你做。var url=根据一键登录所选的地址。
    $.post(url,{"name":"123","pwd":"123"}function(data) {
                if (data == null || data == "") {
                   
                 }
                else {
                   if(data==1){跳转}
                 }
            });
    logina.aspxtry{
    if(page.request.form["name"]!=null&&page.request.form["pwd"]!=null)//这个地方你再严谨些
    {去数据库验证,通过返回1}
    }catch{}
    loginb.aspx同理
      

  8.   

    我倾向于你的第一种javascript方式,也是这样实现的,现在的问题是不知道为什么我用该方法post的时候,出去的却是options方式,而不是post方式.
      

  9.   

    楼主 $post是不能跨域的。我不知道你这几个系统是不是在一个项目里。跨域用$.getJSON(url,json,function(data){alert(data)})
     
      

  10.   


    可能真是这个问题,我是不是一个项目,我是学着自己系统,然后跳过其它系统的登录页面到特定页面,如果用getJSON的话,它是get方式,我这好象只能用post方式.
      

  11.   


    一句话,你能不能改其他系统的登录界面的代码?logina.aspx  loginb.aspx
      

  12.   

    如果对方没有frame判断的话,试试在一个隐藏的iframe里面POST登陆,onload后top.location跳转