首页 新闻 赞助 找找看

如何模拟登录网站 给我思路就可以 分不多就这些了 小弟在此先谢谢

0
悬赏园豆:15 [已关闭问题] 关闭于 2011-07-11 09:30

我要完成功能是模拟登录久游网

https://passport.9you.com/login.php

说明:

  1. 提交的地址是https://login.passport.9you.com/identifyingCode.jsp 这是一个https的地址 牵扯到一些ssl,证书之类的东西. 但是jdk已经集成了的证书,所以就不需要考虑这些,可以当做http来处理.(这是我现在的理解,也可能不对)
  2. 验证码是用户来输入的,暂时不考虑破解问题
  3. 我用HttpAnalyzerStdV5(这是一个http截包工具,下载地址http://idc218.newhua.com/down/HttpAnalyzerFullV5_Trial.zip)对一次请求过程截包:
    发现需要提交图中的这些数据 userName,password,identityingCode.就是用户名,密码,验证码,
    id,continue,userIP,s都是隐藏的数据可以从源文件中看的到,
    但是最后的x和y的值看不到,我测试了几次发现他是鼠标在登陆按钮那个图片的坐标
    我猜现在登陆不成功就是这里的问题,但是这两个值在form中和js中查看不到
  4. 测试账号jiuyoumoni 密码111111
  5. 我的这这样做的

a)         根据 https://login.passport.9you.com/identifyingCode.jsp 下载图片并记录他的cookie 这个值要填入下一个请求的地址中

b)         组织以下数据并提交的https://login.passport.9you.com/checkCode


这个时候X和Y的值无法确定,也不能随便填一个
我的QQ19739257 可以随时联系我

以下的可执行代码,运行的时候在c盘下面建立文件夹CheckCode 验证码放到这个文件夹里

import java.awt.image.BufferedImage;

import java.io.BufferedReader;

import java.io.DataOutputStream;

import java.io.File;

import java.io.InputStreamReader;

import java.net.HttpURLConnection;

import java.net.URL;

import java.net.URLEncoder;

import java.util.Scanner;

import javax.imageio.ImageIO;

import javax.net.ssl.HttpsURLConnection;

public class tempClass {

    public static void Login() {

        try {

            // 下载验证码到本地

            URL url = new URL("https://login.passport.9you.com/identifyingCode.jsp");

            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

            connection.setUseCaches(false);

            connection.setDoOutput(true);

            connection.setDoInput(true);

            connection.setConnectTimeout(5000);

            connection.setReadTimeout(10000);

            ((HttpURLConnection) connection).setRequestMethod("POST");

            connection.setRequestProperty("User-Agent",

                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");

            connection.connect();

            String cookies = connection.getHeaderField("Set-Cookie");

            if (cookies.indexOf(";") != -1) {

                cookies = cookies.substring(0, cookies.indexOf(";"));

            }

            File imgCodeFile = new File("c:\\CheckCode\\"

                    + System.currentTimeMillis() + ".gif");

            BufferedImage image = ImageIO.read(connection.getInputStream());

            ImageIO.write(image, "gif", imgCodeFile);

            String checkCode = GetCheckCode();

            System.out.println(checkCode);

            // 登录

            //隐藏参数

            String id = "SSO_PAY";

            String s = "5384a672b08ac3e96ad534ac67e30442";

            String userIp = "60.191.73.11";//这个是我的ip地址 到时候根据你自己的ip来填写 可以从form里查看值

            String nextUrl = "http://pay.9you.com/funpay/checkstat.php";

            nextUrl = URLEncoder.encode(nextUrl, "GBK");

            //用户要输入值

            String userName = "jiuyoumoni";

            String password = "111111";

            String identifyingCode = checkCode;

            //生成地址https://login.passport.9you.com/checkCode?id=SSO_PAY&s=5384a672b08ac3e96ad534ac67e30442&userIp=60.191.73.11&userName=zhao88zhao8&password=458458&identifyingCode=5pre

            String paramStr = "?" + "id=" + id + "&s=" + s + "&userIp=" + userIp + "&userName=" + userName + "&password=" + password + "&identifyingCode=" + identifyingCode;

            String loginUrl = "https://login.passport.9you.com/checkCode" + paramStr;

            System.out.println("请求地址:" + loginUrl);

            //根据

            url = new URL("https://login.passport.9you.com/checkCode");

            connection = (HttpsURLConnection) url.openConnection();

            connection.setUseCaches(false);

            connection.setDoOutput(true);

            connection.setDoInput(true);

            connection.setConnectTimeout(20000);

            connection.setReadTimeout(20000);

            connection.setRequestMethod("POST");

            connection.setRequestProperty("Content-Type",

                    "application/x-www-form-urlencoded");

            connection.setRequestProperty("Content-Length", String.valueOf(paramStr.length()));

            connection.setRequestProperty("Cookie", cookies);

            connection.setRequestProperty("User-Agent",

                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows 2000)");

            connection.connect();

            DataOutputStream dos = new DataOutputStream(connection.getOutputStream());

            dos.writeBytes(paramStr);

            dos.flush();

            dos.close();

            int res = connection.getResponseCode();

            if (res == 200) {

                BufferedReader in = new BufferedReader(new InputStreamReader(

                        connection.getInputStream(), "GBK"));

                String retVal;

                while ((retVal = in.readLine()) != null) {

                    System.out.println(retVal);

                }

            }

        } catch (Exception e) {

            System.out.println("code error");

        }

    }

    private static String GetCheckCode() {

        Scanner sc = new Scanner(System.in);

        System.out.print("验证码在C:\\ImageCode目录下 ,请你查看并输入:");

        String checkCode = sc.next();

        System.out.println("您输入的验证码是:" + checkCode);

        return checkCode;

    }

    public static void main(String[] args) {

        tempClass.Login();

    }

}

段启锋的主页 段启锋 | 初学一级 | 园豆:125
提问于:2011-06-29 09:26
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册