package com.example.wisdom.lianxi0921.util; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; /** * Created by Administrator on 2017/9/19. */ public class NetUtils { public static String getNetData(String path){ String result = ""; try { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); int code = conn.getResponseCode(); if(code == 200){ InputStream is = conn.getInputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); int len = -1; byte[] buff = new byte[1024]; while((len = is.read(buff)) != -1){ bos.write(buff, 0, len); } result = new String(bos.toByteArray()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; } }
NetUtils
最新推荐文章于 2023-11-27 14:52:36 发布