android 网络请求获得返回数据(1)

来源:互联网 发布:男科网络咨询说话技巧 编辑:程序博客网 时间:2024/04/26 14:43


public class test{    public static void main(String args[]) throws Exception {        URL u=new URL("http://xxxxxxxx");        InputStream in=u.openStream();        ByteArrayOutputStream out=new ByteArrayOutputStream();        try {            byte buf[]=new byte[1024];            int read = 0;            while ((read = in.read(buf)) > 0) {                out.write(buf, 0, read);            }        }  finally {            if (in != null) {                in.close();            }        }        byte b[]=out.toByteArray( );        System.out.println(new String(b,"utf-8"));    }}
public class test{    public static void main(String args[]) throws Exception {        URL u=new URL("http://api.k780.com:88/?app=weather.history&weaid=城市编号(1)&date=查询的日期(2015-07-20)&appkey={APPKEY}&sign={SIGN}&format=json");        InputStream in=u.openStream();        ByteArrayOutputStream out=new ByteArrayOutputStream();        try {            byte buf[]=new byte[1024];            int read = 0;            while ((read = in.read(buf)) > 0) {                out.write(buf, 0, read);            }        }  finally {            if (in != null) {                in.close();            }        }        byte b[]=out.toByteArray( );        System.out.println(new String(b,"utf-8"));    }}
0 0
原创粉丝点击