GetDemo项目目录

采用get方式提交数据到服务器实例

一、编写StreamTools.java

/**
 * 
 */
package com.hyzhou.getdemo.utiils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;


/**
 * @author hyzhou
 *
 * 2013-11-6
 */
public class StreamTools {

    /**
     * 把输入流内容转化成字符串
     */
    public static String readInputStream(InputStream is) {        
        try {
            ByteArrayOutputStream baos=new ByteArrayOutputStream();
            int len=0;
            byte[] buffer=new byte[1024];
            while ((len=is.read(buffer))!=-1) {
                baos.write(buffer,0,len);
            }
            is.close();
            baos.close();
            byte[] result=baos.toByteArray();
            //试着解析result中的字符串
            String temp=new String(result);
            return temp;
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
            return "获取失败";
        }
        
    }
}
View Code

相关文章: