List of utility methods to do URL Query
int | query(URL host, String endpoint, String customer, String name, OutputStream out) query String f1 = (customer == null) ? null : "customer=" + customer; String f2 = (name == null) ? null : "name=" + name; String filter = ((f1 == null) ? "?" : "?" + f1 + "&") + ((f2 == null) ? "" : f2); URL url = new URL(host, endpoint + filter); int responseCode; HttpURLConnection connection = null; InputStream input = null; try { ... |
String | queryEndpoint(String url) Query an endpoint. HttpURLConnection.setFollowRedirects(false); HttpURLConnection conn = null; BufferedReader ins; StringBuilder outs = new StringBuilder(); char[] buffer = new char[1024]; String text = null; int tmpi; try { ... |
String | appendQueryParams(String url, Map Append query parameters to given url String fullUrl = new String(url); if (params != null) { boolean first = (fullUrl.indexOf('?') == -1); for (String param : params.keySet()) { if (first) { fullUrl += '?'; first = false; } else { ... |
String | getHTTPQuery(String urlToRead) get HTTP Query URL url; HttpURLConnection conn; BufferedReader rd; String line; String result = ""; try { url = new URL(urlToRead); conn = (HttpURLConnection) url.openConnection(); ... |
Map | getQueryParams(String url) Retrieve the query parameters from given url Map<String, String> params = new HashMap<String, String>(); int start = url.indexOf('?'); while (start != -1) { int equals = url.indexOf('=', start); String param = ""; if (equals != -1) { param = url.substring(start + 1, equals); } else { ... |
String | queryHtml(String url) query Html HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setInstanceFollowRedirects(true); int code = connection.getResponseCode(); if (code == 200) { InputStream in = connection.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; ... |
List | search(String query, int numberOfUrls) search List<String> listOfURLs = new ArrayList<String>(); String APIkey = "AIzaSyDNZ6K2wI2z2-j1tTSaZrpgUQJpOV2DRv8"; query = URLEncoder.encode(query, "UTF-8"); String stringURL = "https://www.googleapis.com/customsearch/v1?key=" + APIkey + "&cx=013036536707430787589:_pqjad5hr1a&q=" + query + "&alt=json"; URL url = new URL(stringURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); ... |