package network; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class HttpWork { public static String gethttpwork(String mpath, String gets) { String messages=""; try { URL url=new URL(mpath); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(gets); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); if ((connection.getResponseCode())==200){ InputStream inputStream = connection.getInputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] bytes = new byte[1024 * 512]; int len=0; while ((len=inputStream.read(bytes))>-1){ outputStream.write(bytes,0,len); } messages=outputStream.toString(); inputStream.close(); connection.disconnect(); } } catch (Exception e) { e.printStackTrace(); } return messages; } }
HttpWork
最新推荐文章于 2024-07-22 22:55:47 发布