Android 索引处的查询中存在非法字符
我正在使用Android 索引处的查询中存在非法字符,android,Android,我正在使用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
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());
}
您需要对URL进行编码 像这样,
try {
String simpleUrl = "http://www.abc.com/?email=abc&pass=efg";
String encodedurl = URLEncoder.encode(url,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
现在将
encodedurl
String传递给newhttpget(encodedurl)
发布查询字符串以查找索引12904-29 11:30:56.514:V/Exception(7745):索引129:04-29 11:30:56.514:V/Exception(7745)查询中的非法字符:rwrQMYYRv88Y9WZUleXQjgKA8NBuq5DkaA04-29 11:45:02.421:V/Exception(9040):目标主机不能为null,也不能在参数中设置。scheme=null,host=null,path=paste您的url字符串?04-29 11:47:41.069:V/encodedeo url(9369):http%3A%2F%2F192.168.1.43%2FEnc%2Fexamples%2Fdecrypt.php%3FMessage%3dawfpwEx9xxntmfga8ufgsqpr3ajfqwwwymsy%2bqt2wbs8ft6ntmytn91riowkgmar6rwnz370tn4l%0Ac%2fdmtl1%2fdydpdg96ysnpkuh0ju9r%kka%0A04-499:93v文本密码:请在开头添加http://
或https://
。注意:此url在网络上不存在,请使用有效路径。它给出404错误意味着url不存在。
String link="http://example.php?string1="+URLEncoder.encode(string1)+"&string2="+URLEncoder
.encode(string2)+"&string3="+URLEncoder.encode(string3)+"&string4="+URLEncoder.encode(string4)+"";