在我们使用HttpClient对象的时候,经常会有一些拼接参数出现中文字符等等非法字符,例如一下问题:
http://apilocate.aaa.com/position?macs=50:64:2b:61:81:b8,-58,WIFI00|30:5a:3a:c5:8d:d8,-65,WIFI01|c2:a5:dd:60:04:de,-77,WIFI02|00:11:b5:84:c1:aa,-79,WIFI03|22:11:b5:84:c1:aa,-80,WIFI04|12:11:b5:84:c1:aa,-80,WIFI05
我们只需要把macs=后的数据通过URLEncoder进行转编码即可
解决方案如下:
param1 = URLEncoder.encode(param1, "UTF-8");
把参数传入进行转编码后再放入到url内即可
编码后的url如下所示:
http://apilocate.aaa.com/position?macs=50%3A64%3A2b%3A61%3A81%3Ab8%2C-58%2CWIFI00%7C30%3A5a%3A3a%3Ac5%3A8d%3Ad8%2C-65%2CWIFI01%7Cc2%3Aa5%3Add%3A60%3A04%3Ade%2C-77%2CWIFI02%7C00%3A11%3Ab5%3A84%3Ac1%3Aaa%2C-79%2CWIFI03%7C22%3A11%3Ab5%3A84%3Ac1%3Aaa%2C-80%2CWIFI04%7C12%3A11%3Ab5%3A84%3Ac1%3Aaa%2C-80%2CWIFI05
?
|