2013年9月2日星期一

Use URLDecoder.decode reported URLDecoder: Illegal hex charactersin escape (%) pattern -

Use URLDecoder.decode () method accepts parameters if the parameter containing " % " this character , it will throw an exception java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape ( %) pattern -,
I do not know how to solve , seeking master wing solutions, online search, too , as the company restricted site , all to no avail solutions

Code:

If these two front -Senate
oid = 37729 & sendReson = Yes % Try

private HashMap getRequestParamByPost ()
{
HashMap paraMap = new HashMap ();
try
{
String requestJson = URLDecoder.decode (
this.getRequestJsonObject () == null? "": this
. getRequestJsonObject () , "UTF-8")
;
this.log.info (requestJson);
if (requestJson! = null &&! requestJson.equals ( " " ) )
{
String [] requestJsonArr = requestJson.split ( "&" ) ;
String [] tempArr = null;
for (String str: requestJsonArr)
{
tempArr = str . split ("=");
if (tempArr! = null && tempArr.length == 2)
{
paraMap.put (tempArr [0], tempArr [1]);
}
}
}
}
catch (UnsupportedEncodingException e)
{
this.log.error (" Get post Parameter Error :" + e) ;
}
return paraMap;
}

code red part of the place being given , in addition to using other characters replace% , there are other solutions do
------ Solution ------------- -------------------------------
pass parameters when using encodeURIComponent (" yes % try" )
% were considered to be escaped markup URL , URL specification has its own rules , will be escaped as % 25 % ! You are % followed a Chinese character, which it was found to be escaped '% test ' is that it does not know , give you being given !
------ Solution ---------------------------------------- ----

using base64 is a good choice !
------ Solution ---------------------------------------- ----
Java6 comes with a jar package , as long as the quote below:
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
* Base64解密
* @param key
* @return
* @throws Exception
*/
public static byte[] decoderBase64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}

/**
* Base64加密
* @param key
* @return
* @throws Exception
*/
public static String encoderBase64(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}

------ For reference only ----------------------------------- ----
can consider using base64 transcoding parameters , after receiving the decoded just fine.
------ For reference only -------------------------------------- -
base64 how to use ? Give Liezi
------ For reference only ----------------------------------- ----

learned , yes.

没有评论:

发表评论