日期:2014-05-17  浏览次数:20684 次

模拟登陆实现不了!!!求指教!100分哦!
本帖最后由 xyz 于 2013-06-30 22:08:12 编辑

import java.awt.image.BufferedImage; 
import java.io.BufferedReader; 
import java.io.DataOutputStream; 
import java.io.File; 
import java.io.InputStreamReader; 
import java.net.HttpURLConnection; 
import java.net.URL; 
import java.net.URLEncoder; 
import java.util.Scanner; 
import javax.imageio.ImageIO; 
import javax.net.ssl.HttpsURLConnection;//这句貌似没有用到!
public class wangrongfeng 


    public static void Login() throws Exception
    { 
        
            // 下载验证码到本地 
            URL url = new URL("http://5pi.cn/code.php"); 
            HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
            connection.setUseCaches(false); 
            connection.setDoOutput(true); 
            connection.setDoInput(true); 
            connection.setConnectTimeout(5000); 
            connection.setReadTimeout(10000); 
            ((HttpURLConnection) connection).setRequestMethod("GET"); 
            connection.setRequestProperty("User-Agent", 
                    "Mozilla/5.0 (compatible; MSIE 8.0; Windows 7)"); 
            connection.connect(); 

            String cookies = connection.getHeaderField("Set-Cookie"); 
            if (cookies!= null) 
            { 
                cookies = cookies.substring(0, cookies.indexOf(";")); 
            }