Here you can find the source of request(String httpUrl, Map
public static String request(String httpUrl, Map<String, String> httpArgMap)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Map; import java.util.Set; public class Main { public static String request(String httpUrl, Map<String, String> httpArgMap) { return request(httpUrl, httpArgMap, null); }//w ww . j a v a 2 s . co m public static String request(String httpUrl, Map<String, String> httpArgMap, String apikey) { BufferedReader reader = null; String result = null; StringBuffer sbf = new StringBuffer(); httpUrl = httpUrl + "?"; Set<String> keySet = httpArgMap.keySet(); for (String string : keySet) { httpUrl = httpUrl + string + "=" + httpArgMap.get(string) + "&"; } httpUrl = httpUrl.replaceAll(" ", ""); try { URL url = new URL(httpUrl.substring(0, httpUrl.length() - 1)); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); if (apikey != null) { connection.setRequestProperty("apikey", apikey); } connection.connect(); InputStream is = connection.getInputStream(); reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); String strRead = null; while ((strRead = reader.readLine()) != null) { sbf.append(strRead); sbf.append("\r\n"); } reader.close(); result = sbf.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } }