gpt4 book ai didi

android - 索引查询中的非法字符

转载 作者:行者123 更新时间:2023-11-29 21:09:37 25 4
gpt4 key购买 nike

我正在使用 HTTPGET 请求从服务器获取数据。当我传递 url ir 给我错误

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

但我在浏览器上点击 url 它给了我正确的响应

我正在为 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());
}

最佳答案

您需要对您的网址进行编码

像这样,

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);

关于android - 索引查询中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23356771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com