登录网页java程序

/**

 *Login page with httpclient3.1

*/

import java.io.*;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class JLoginTest
{
    public static void main(String args[])
        throws HttpException, IOException
    {
      // ·¢̍postȫȳµȂ½
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost("cws.namtai.com.cn", 80, "http");
        PostMethod post = new PostMethod("/names.nsf?Login");
        NameValuePair name = new NameValuePair("Username", "lmyin");
        NameValuePair pass = new NameValuePair("Password", "yyts619");
       
        //ЂĦµŖµ¶ԶՓڵ¥´¿µĵȂ½²»ˇ±ِ趄¡£
        NameValuePair param5 = new NameValuePair("domain", "ntsz");
        NameValuePair param6 = new NameValuePair("language", "zh-cn");
        //½«ֵ¶ԼԈ숫ȳͥ
        post.setRequestBody(new NameValuePair[] {name, pass ,param5,param6});
        int status = client.executeMethod(post);
        post.releaseConnection();
       
        // ҩ֤cookie
        CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
        Cookie cookies[] = cookiespec.match("cws.namtai.com.cn", 80, "/", false, client.getState().getCookies());
        if(cookies.length == 0)
        {
            System.out.println("None");
        } else
        {
            for(int i = 0; i < cookies.length; i++)
                System.out.println((new StringBuilder()).append("========================================================/n").append(cookies[i].toString()).append("/n========================================================").toString());

        }
       
        // ¿ªʼȫȳҳĦ
        GetMethod get = new GetMethod("http://cws.namtai.com.cn/lks/koa/lks_d2601.nsf/VD_ByClass/338BFFBD6070EA9A4825742500210E94?opendocument&m_Seq=0.9021852269941022");
        get.setRequestHeader("Content-type", "text/html; charset=UTF-8");
        client.executeMethod(get);             
        byte responseBody[] = get.getResponseBody();       
        String response = new String(responseBody);
        File f=new File("JLoginTest.htm");
       FileOutputStream fos=new FileOutputStream(f);
       fos.write(responseBody);
       fos.close();
        System.out.println((new StringBuilder()).append("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++/n").append(response).append("/n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++").toString());
        get.releaseConnection();      
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值