[解决方案]java.net.URISyntaxException: Illegal character in query at index

 

导致这种错误的原因是因为URL没有进行编码,URL不识别你提供的URL字符串
String test = "{hello world!}";
String testEncode = URLEncoder. encode(test, "utf-8" );
String testDecode = URLDecoder.decode(testEncode, "utf-8");
System. out .println(test);
System. out .println(testEncode);
System. out .println(testDecode);
 返回结果:
{hello world!}
%7Bhello+world%21%7D
{hello world!}
 

 

你可能感兴趣的:(JAVA,java,url,编码)