大概思路就是把汉字转成utf编码,服务端反转即可,编码是百分号分隔的,例如“白晓哲”转为“%E7%99%BD%E6%99%93%E5%93%B2” ,这种做法不依赖服务器的配置和转码过滤器,有效避免乱码
编码方法:
let astr="白晓哲" let urlstr= stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())
在服务器端转回汉字(tomcat java):
try { String realName=request.getParameter("nm") realName = URLDecoder.decode(realName,"UTF-8"); }catch (Exception e){ logger.warn(e.getMessage()); }