通过rul读取流数据此条适用于 webservice-restful 执行接口

package com.newegg.frontservice.test;

import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.JarURLConnection;
import java.net.URL;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class URLConnectionTest {
    public static void main(String []args){
       try{
           /*
            *   方法一
            *     
           URL url = new URL("http://www.sina.com.cn");
           URLConnection urlcon = url.openConnection();
           InputStream is = urlcon.getInputStream();
            */
          
           /*
            * 方法二
            *
            * URL url = new URL("http://www.yhfund.com.cn");
           HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
           InputStream is = urlcon.getInputStream();
            */
          
          
          
           /*
            * 方法三
            * URL url = new URL("http://www.yhfund.com.cn");
           InputStream is = url.openStream();
            */
           long begintime = System.currentTimeMillis();
          
           URL url = new URL("aaa");
           HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
           urlcon.connect();         //获取连接
           InputStream is = urlcon.getInputStream();
           BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
           StringBuffer bs = new StringBuffer();
           String l = null;
           while((l=buffer.readLine())!=null){
               bs.append(l).append("/n");
           }
           System.out.println(bs.toString());
          
           //System.out.println(" content-encode:"+urlcon.getContentEncoding());
           //System.out.println(" content-length:"+urlcon.getContentLength());
           //System.out.println(" content-type:"+urlcon.getContentType());
           //System.out.println(" date:"+urlcon.getDate());
      
          
           System.out.println("总共执行时间为:"+(System.currentTimeMillis()-begintime)+"毫秒");
        }catch(IOException e){
           System.out.println(e);
       }
    }
 
}

相关文章

1.使用ajax调用varxhr;functioninvoke(){if(window.ActiveXO...
               好不容易把WebService服务器...
1新建一个工程项目用来做服务端增加一个MyService1类文件pac...
packagecom.transsion.util;importjava.io.BufferedReader;i...
再生产wsdl文件时重写描述文件1usingSystem;2usingSystem.Co...
一般情况下,使用eclipse自带的jax-ws生成webservice会自动生...