当前位置:编程学习 > JAVA >>

谁能告诉我这段代码到底能不能登陆啊

import java.io.*;   
import java.util.*;   
import java.net.*;   
  
public class WebTest {   
  
    public static void main(String[] args) {   
  
        System.out.println("beging...");   
        DownLoadPages("http://login.xiaonei.com/Login.do", "d:/fileDown.txt");   
        System.out.println("end.");   
    }   
  
    public static void DownLoadPages(String urlStr, String outPath) {   
        int chByte = 0;   
  
        URL url = null;   
  
        HttpURLConnection httpConn = null;   
  
        InputStream in = null;   
  
        FileOutputStream out = null;   
  
        try {   
            String post = "email=" + URLEncoder.encode("1284198179@qq.com", "UTF-8")   
                    + "&password=" + "TXWSzhb139";   
            url = new URL(urlStr);   
  
            httpConn = (HttpURLConnection) url.openConnection();   
  
            httpConn.setFollowRedirects(false);   
  
            //inorder to disable the redirects   
            httpConn.setInstanceFollowRedirects(false);   
  
            httpConn.setDoOutput(true);   
            httpConn.setDoInput(true);   
            httpConn.setRequestProperty("User-Agent",   
                    "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT)");   
            httpConn.setRequestProperty("Content-Type",   
                    "application/x-www-form-urlencoded");   
  
            //ok now, we can post it   
            PrintStream send = new PrintStream(httpConn.getOutputStream());   
            send.print(post);   
            send.close();   
            URL newURL = new URL(httpConn.getHeaderField("Location"));   
            System.out.println("the URL has move to "  
                    + httpConn.getHeaderField("Location"));   
            httpConn.disconnect();   
  
            //           OK, now we are ready to get the cookies out of the URLConnection      
            String cookies = getCookies(httpConn);   
            System.out.println(cookies);   
            httpConn = (HttpURLConnection) newURL.openConnection();   
            httpConn.setRequestProperty("User-Agent",   
                    "Mozilla/5.0 (compatible; MSIE 6.0; Windows NT)");   
            httpConn.setRequestProperty("Content-Type",   
                    "application/x-www-form-urlencoded");   
            httpConn.setRequestProperty("Cookie", cookies);   
  
            httpConn.setDoInput(true);   
            in = httpConn.getInputStream();   
            out = new FileOutputStream(new File(outPath));   
  
            chByte = in.read();   
            while (chByte != -1) {   
                out.write(chByte);    
                chByte = in.read();   
            }   
        } catch (Exception e) {   
            e.printStackTrace();   
        }   
    }   
  
    public static String getCookies(HttpURLConnection conn) {   
        StringBuffer cookies = new StringBuffer();   
        String headName;   
        for (int i = 7; (headName = conn.getHeaderField(i)) != null; i++) {   
            StringTokenizer st = new StringTokenizer(headName, "; ");           
            while (st.hasMoreTokens()) {   
                cookies.append(st.nextToken() + "; ");   
            }   
        }   
        return cookies.toString();   
    }   
}   --------------------编程问答-------------------- 代码能不能登录我就不知道,不过用户名1284198179@qq.com加密码TXWSzhb139能在人人网登录,如果是你自己的,赶紧改密码吧 --------------------编程问答-------------------- 我也看不出来,不过这个用户名的密码确实应该要改了。 --------------------编程问答-------------------- lz 赶紧改密码把。。 --------------------编程问答-------------------- 可以在“人人网登录”。
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,