轻源码

  • QingYuanMa.com
  • 全球最大的互联网技术和资源下载平台
搜索
一起源码网 门户 电脑主程序开源 查看主题

android解析JSON,XML数据的请求网络工具类

发布者: ccttvv | 发布时间: 2017-12-23 06:20| 查看数: 2322| 评论数: 1|帖子模式

安卓中像解析一些JSON,XML文件用到的请求网络的工具类,很方便

<span style="font-size:18px;">package com.example.login;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class AA {
	public static String requestHttp(String path)
	{
		ByteArrayOutputStream bo=new ByteArrayOutputStream();
		try 
		{
			URL url=new URL(path);
			HttpURLConnection con=(HttpURLConnection) url.openConnection();
			con.setConnectTimeout(5000);
			con.setDoInput(true);
			con.connect();
			if(con.getResponseCode()==200)
			{
				InputStream in = con.getInputStream();
				int count=0;
				byte b[]=new byte[1024];
				while((count=in.read(b))!=-1)
				{
					bo.write(b, 0, count);
					bo.flush();
				}
			}
			return bo.toString();
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		return null;
		
	}
}
</span>


最新评论

我爱金羊 发表于 2022-5-6 11:18
音乐app下载

轻源码让程序更轻更快

QingYuanMa.com

工作时间 周一至周六 8:00-17:30

侵权处理

客服QQ点击咨询

关注抖音号

定期抽VIP

Copyright © 2016-2021 https://www.171739.xyz/ 滇ICP备13200218号

快速回复 返回顶部 返回列表