HttpClient 模拟用户操作

首先模拟用户登录:

    /**
     * 模拟用户登录
     * 
     */
    private void login() throws HttpException, IOException {
        PostMethod loginPost = new PostMethod("http://localhost:8080/slsint_hn/loginAction.do?method=login");
        NameValuePair[] loginData = {
                new NameValuePair("logonname", "admin"),
                new NameValuePair("password", "admin"),
                new NameValuePair("logindate",
                        MessageUtil.REPORT_OL_SDF.format(new Date())) };
        loginPost.setRequestBody(loginData);
        httpClient.executeMethod(loginPost);
        // 释放链接
        loginPost.releaseConnection();
View Code

之后点击一个菜单:

        PostMethod repDataPost = new PostMethod("http://localhost:8080/slsint_hn/dataBuild.do?method=buildDataForm");
        httpClient.executeMethod(repDataPost);
        repDataPost.releaseConnection();
View Code

然后点击一个按钮:

    private void repBuild(Date repA3702DXDate) throws HttpException,
            IOException {

        PostMethod repBuildPost = new PostMethod("http://localhost:8080/slsint_hn/dataBuild.do?method=build");
        NameValuePair[] repData = {
                new NameValuePair("organ", MessageUtil.ORGAN_ID),
                new NameValuePair("report", MessageUtil.REPORT_ID),
                new NameValuePair("reportType", MessageUtil.REPORT_TYPE),
                new NameValuePair("date",
                        MessageUtil.REPORT_OL_SDF.format(repA3702DXDate)) };
        repBuildPost.setRequestBody(repData);
        httpClient.executeMethod(repBuildPost);
        repBuildPost.releaseConnection();
    }
View Code


写URL的时候一定要注意,如果URL写错了,比如多写了一个“/”,

程序会发生 JSessionID 不是同一个的错误。

 

posted @ 2015-12-28 15:35  何鸿涛  阅读(1530)  评论(0)    收藏  举报