[Android] java.lang.IllegalArgumentException: Illegal character in query at index 57

来源:互联网 发布:php 输出源代码 编辑:程序博客网 时间:2024/06/15 13:46
对于使用GET带参数请求的方式,如果URL中出现非法字符比如"[",这时候使用java.net.URLEncoder的encode()方法对其进行编码:


   
<span style="white-space:pre"></span>String encodeData = URLEncoder.encode(data, "UTF-8");    String curi = IP_STRING + operateUrl + "?"+"data="+encodeData;HttpGet httpGet = new HttpGet(curi);HttpResponse response = client.execute(httpGet);String result = EntityUtils.toString(response.getEntity(), "UTF-8");


0 0
原创粉丝点击