public String execute() throws IOException {

        if (CBStringUtil.isEmptyOrNull(this.url)) {
            return null;
        }

        StringBuilder netString = new StringBuilder();
        URL url = new URL(this.url);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        //设置请求方法
        conn.setRequestMethod(method.value);

        //设置头部
        for (Map.Entry<String, String> item : header.entrySet()) {
            conn.setRequestProperty(item.getKey(), item.getValue());
        }

        //保持session的把设置cookie
        if (keepSession && !CBStringUtil.isEmptyOrNull(cookie) && !header.containsKey(CBHeader.COOKIE)
                && !pauseSessionForOnce) {
            conn.setRequestProperty(CBHeader.COOKIE, cookie);
        }

        pauseSessionForOnce = false;

        //设置超时时间
        conn.setConnectTimeout(timeout);
        conn.setReadTimeout(timeout);

        //设置跳转
        conn.setInstanceFollowRedirects(followRedirects);

        if (method == CBMethod.POST && !CBStringUtil.isEmptyOrNull(data)) {
            conn.setDoOutput(true);
            OutputStream out = conn.getOutputStream();
            out.write(data.getBytes());
            out.flush();
            out.close();
        }
        BufferedReader buff = new BufferedReader(new InputStreamReader(
                conn.getInputStream(), charset));
        String line;
        while ((line = buff.readLine()) != null) {
            netString.append("\n");
            netString.append(line);
        }
        buff.close();

        //记录cookie值,用于下次传递
        String tmpCookie = conn.getHeaderField(CBHeader.SET_COOKIE);
        if (keepSession && CBStringUtil.isEmptyOrNull(cookie) && !CBStringUtil.isEmptyOrNull(tmpCookie)) {
            cookie = tmpCookie;
        }
        return netString.length() > 0 ? netString.substring(1) : netString.toString();
    }
public String execute() throws IOException {

        if (CBStringUtil.isEmptyOrNull(this.url)) {
            return null;
        }

        StringBuilder netString = new StringBuilder();
        URL url = new URL(this.url);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        
        conn.setRequestMethod(method.value);

        
        for (Map.Entry<String, String> item : header.entrySet()) {
            conn.setRequestProperty(item.getKey(), item.getValue());
        }

        
        if (keepSession && !CBStringUtil.isEmptyOrNull(cookie) && !header.containsKey(CBHeader.COOKIE)
                && !pauseSessionForOnce) {
            conn.setRequestProperty(CBHeader.COOKIE, cookie);
        }

        pauseSessionForOnce = false;

        
        conn.setConnectTimeout(timeout);
        conn.setReadTimeout(timeout);

        
        conn.setInstanceFollowRedirects(followRedirects);

        if (method == CBMethod.POST && !CBStringUtil.isEmptyOrNull(data)) {
            conn.setDoOutput(true);
            OutputStream out = conn.getOutputStream();
            out.write(data.getBytes());
            out.flush();
            out.close();
        }
        BufferedReader buff = new BufferedReader(new InputStreamReader(
                conn.getInputStream(), charset));
        String line;
        while ((line = buff.readLine()) != null) {
            netString.append("\n");
            netString.append(line);
        }
        buff.close();

        
        String tmpCookie = conn.getHeaderField(CBHeader.SET_COOKIE);
        if (keepSession && CBStringUtil.isEmptyOrNull(cookie) && !CBStringUtil.isEmptyOrNull(tmpCookie)) {
            cookie = tmpCookie;
        }
        return netString.length() > 0 ? netString.substring(1) : netString.toString();
    }
public String execute ( ) throws IOException { if ( CBStringUtil . isEmptyOrNull ( this . url ) ) { return null ; } StringBuilder netString = new StringBuilder ( ) ; URL url = new URL ( this . url ) ; HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; //设置请求方法 conn . setRequestMethod ( method . value ) ; //设置头部 for ( Map . Entry < String , String > item : header . entrySet ( ) ) { conn . setRequestProperty ( item . getKey ( ) , item . getValue ( ) ) ; } //保持session的把设置cookie if ( keepSession && ! CBStringUtil . isEmptyOrNull ( cookie ) && ! header . containsKey ( CBHeader . COOKIE ) && ! pauseSessionForOnce ) { conn . setRequestProperty ( CBHeader . COOKIE , cookie ) ; } pauseSessionForOnce = false ; //设置超时时间 conn . setConnectTimeout ( timeout ) ; conn . setReadTimeout ( timeout ) ; //设置跳转 conn . setInstanceFollowRedirects ( followRedirects ) ; if ( method == CBMethod . POST && ! CBStringUtil . isEmptyOrNull ( data ) ) { conn . setDoOutput ( true ) ; OutputStream out = conn . getOutputStream ( ) ; out . write ( data . getBytes ( ) ) ; out . flush ( ) ; out . close ( ) ; } BufferedReader buff = new BufferedReader ( new InputStreamReader ( conn . getInputStream ( ) , charset ) ) ; String line ; while ( ( line = buff . readLine ( ) ) != null ) { netString . append ( "\n" ) ; netString . append ( line ) ; } buff . close ( ) ; //记录cookie值,用于下次传递 String tmpCookie = conn . getHeaderField ( CBHeader . SET_COOKIE ) ; if ( keepSession && CBStringUtil . isEmptyOrNull ( cookie ) && ! CBStringUtil . isEmptyOrNull ( tmpCookie ) ) { cookie = tmpCookie ; } return netString . length ( ) > 0 ? netString . substring ( 1 ) : netString . toString ( ) ; }
获取网页的内容

@return 网页/目标源码
@throws IOException 异常
获取网页的内容