码迷,mamicode.com
首页 > 其他好文 > 详细

模拟登录学校邮箱

时间:2015-11-10 00:14:35      阅读:339      评论:0      收藏:0      [点我收藏+]

标签:

  要模拟登录的post地址(url),可以先登录一边要登录的网站,用wireshark抓取信息,filter过滤条件为http.request.method==POST。

  也可以在Chrome浏览器打开,按f12,点击Network,进行查看。

  

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/*
 * Copyright (c) 2015 
 * 广州米所思信息科技有限公司(Guangzhou Misuosi Information technology co., LTD) 
 * All rights reserved.
 */
/**
 * Description        : 
 * <p/>
 * <br><br>Time        : 2015-11-9 下午8:02:01
 *
 * @author ZXL
 * @version 1.0
 * @since 1.0
 */
public class ShoolEmailLogin {
    //portaluser.jsp
    static String surl = "http://www.gduf.edu.cn/portaluser.jsp";
    static String responseCookie ;
    static String username = "账号";
    static String password = "密码";
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        StringBuilder sb = new StringBuilder();
        try {
            URL url = new URL(surl);
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("contentType", "GB2312");  
            
            sb.append("username="+username);
            sb.append("&password="+password);
            conn.setRequestProperty("Content-Length",   
                        String.valueOf(sb.toString().length()));  
            OutputStream os = conn.getOutputStream();
            os.write(sb.toString().getBytes("GB2312"));
            os.close();
            
       //获取返回的信息 BufferedReader bf
= new BufferedReader(new InputStreamReader(conn.getInputStream(),"GB2312")); responseCookie = conn.getHeaderField("Set-Cookie"); System.out.println("Cookie="+responseCookie); String line = null; while ((line=bf.readLine())!=null){ //System.out.println(line); } //读取登录后的页面内容 URL newurl = new URL("http://www.gduf.edu.cn/mail/mail_list.jsp?foldertype=1"); HttpURLConnection httpURLConn = (HttpURLConnection) newurl.openConnection(); httpURLConn.setRequestProperty("Cookie",responseCookie); BufferedReader newBR = new BufferedReader(new InputStreamReader(httpURLConn.getInputStream(),"GB2312")); String newLine = null; while ((newLine = newBR.readLine())!=null){ System.out.println(newLine); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

 

模拟登录学校邮箱

标签:

原文地址:http://www.cnblogs.com/lindaZ/p/4951357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!