After some trial and error, I finally figured it out :
[1] Use this to encode the URL :
public static String encode(String s)
{
try { return URLEncoder.encode(s,"UTF-8"); }
catch (UnsupportedEncodingException e)
{
Resume_App.Save_To_Log("UTF-8 is not a recognized encoding\n"+Tool_Lib_Simple.Get_Stack_Trace(e));
throw new RuntimeException(e);
}
}
[2] Use "exchange.getRequestURI().getRawQuery()" to get the raw query, I was using exchange.getRequestURI().getQuery() eariler, and it decodes the query for me, and made things confusing, what I need is the raw query.
[3] Use the following to get the name value map :
public LinkedHashMap<String,String> queryToMap(String query)
{
LinkedHashMap<String,String> result=new LinkedHashMap();
for (String param : query.split("&"))
{
String pair[]=param.split("=");
if (pair.length>1) result.put(pair[0],pair[1]);
else result.put(pair[0],"");
}
return result;
}
[4] Use the following to get decoded name value pairs :
for (Map.Entry<String,String> entry : params.entrySet())
{
paramName=entry.getKey().replace("+"," ");
try { paramValue=URLDecoder.decode(entry.getValue(),"utf-8"); }
catch (Exception e) { e.printStackTrace(); }
}