Here you can find the source of queryEndpoint(String url)
Parameter | Description |
---|---|
url | the URL of the endpoint |
public static String queryEndpoint(String url)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.*; public class Main { /**/*w ww . j a v a 2s . c om*/ * Query an endpoint. * @param url the URL of the endpoint * @return the text obtained from the endpoint */ public static String queryEndpoint(String url) { HttpURLConnection.setFollowRedirects(false); HttpURLConnection conn = null; BufferedReader ins; StringBuilder outs = new StringBuilder(); char[] buffer = new char[1024]; String text = null; int tmpi; try { conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("Accept", "text/plain"); conn.connect(); ins = new BufferedReader(new InputStreamReader( conn.getInputStream())); do { tmpi = ins.read(buffer, 0, buffer.length); if (tmpi > 0) outs.append(buffer, 0, tmpi); } while (tmpi >= 0); text = outs.toString(); conn.disconnect(); } catch (Exception e) { //e.printStackTrace(); } finally { if (conn != null) conn.disconnect(); } return text; } }