package restclient;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;public class NetClientGet { public static void main(String[] args) { try { URL url = new URL("http://localhost:3002/RestWebserviceDemo/rest/json/product/dynamicData?size=5");//your url i.e fetch data from . HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP Error pre : " + conn.getResponseCode()); } InputStreamReader in = new InputStreamReader(conn.getInputStream()); BufferedReader br = new BufferedReader(in); String output; while ((output = br.readLine()) != null) { System.out.println(output); } conn.disconnect(); } catch (Exception e) { System.out.println("Exception in NetClientGet:- " + e); } }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)