zoukankan      html  css  js  c++  java
  • 模拟登录校内邮箱

    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 
     * 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();
            }
            
        }
    
    }
  • 相关阅读:
    用Python完成一个汇率转换器
    鸿蒙如何用JS开发智能手表App
    鸿蒙如何用JS开发智能手表App
    SAP Spartacus SplitViewComponent Migration 的一个具体例子
    SAP Spartacus B2B 页面 Popover Component 的条件显示逻辑
    SAP Spartacus 升级时关于 schematics 的更新
    SAP Spartacus B2B 页面 Disable 按钮的显示原理
    SAP Spartacus B2B 页面 Disable Confirmation 对话框的显示原理
    通过 Feature Level 动态控制 SAP Spartacus 的页面显示
    SAP Commerce Cloud Build Manifest Components
  • 原文地址:https://www.cnblogs.com/lindaZ/p/4957661.html
Copyright © 2011-2022 走看看