Here you can find the source of constructURLString(Map
Parameter | Description |
---|---|
parameters | a parameter |
private static String constructURLString(Map<String, String> parameters)
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Map; public class Main { /**/* w w w .j av a 2 s. co m*/ * Expand the map of parameters to construct a URL string * * @param parameters * @return */ private static String constructURLString(Map<String, String> parameters) { StringBuffer url = new StringBuffer(); boolean first = true; for (Map.Entry<String, String> entry : parameters.entrySet()) { try { // type checking, we can get nulls in here if ((entry.getValue() == null) || (entry.getKey() == null)) { continue; } if (entry.getValue().length() == 0) { continue; } if (first) { first = false; } else { url.append("&"); } url.append(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8")); } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); // No Fixing this, really throw new Error("Unsupported Encoding Exception", ex); } } return url.toString(); } }