索引中查询中的非法字符

时间:2014-04-29 06:06:42

标签: android

我正在使用HTTPGET请求从服务器获取数据。当我通过网址给我错误

04-29 11:30:56.514: V/Exception(7745): Illegal character in query at index 129

但是我在浏览器上点击它正在给我正确的回复

我正在使用HTTPGET

的以下代码
    DefaultHttpClient httpClient = new DefaultHttpClient();
    try {
        HttpGet httpGet = new HttpGet(url);
        HttpResponse httpResponse = httpClient.execute(httpGet);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
        return processRequest(is).toString();
    } catch (Exception exception) {
        Log.v("Exception", exception.getMessage());
    }

2 个答案:

答案 0 :(得分:2)

您需要对网址进行编码

像这样,

try {

    String simpleUrl = "http://www.abc.com/?email=abc&pass=efg";
    String encodedurl = URLEncoder.encode(url,"UTF-8");

} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
}

现在将encodedurl字符串传递给new HttpGet(encodedurl);

答案 1 :(得分:0)

String link="http://example.php?string1="+URLEncoder.encode(string1)+"&string2="+URLEncoder
.encode(string2)+"&string3="+URLEncoder.encode(string3)+"&string4="+URLEncoder.encode(string4)+"";