从服务器获取json

来源:互联网 发布:java兰陵王破解版 编辑:程序博客网 时间:2024/06/05 15:36
String apiUrl=
"https://www.kuaidi100.com/query?type=shentong&postid=227728570456";
URL url=new URL(apiUrl);
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
InputStream is=conn.getInputStream();
byte []temp=new byte[1024];
int length=0;
ByteArrayOutputStream baos=new ByteArrayOutputStream();
while ((length=is.read(temp))!=-1){
    baos.write(temp,0,length);
}
json=baos.toString();
Message msg=new Message();
msg.what=1;
msg.obj=json;
handler.sendMessage(msg);
记得注册联网权限
原创粉丝点击