[英]Java IllegalArgumentException Illegal character in query at index
I'm using the code below, which works fine when I use http://stackoverflow.com/
. 我正在使用下面的代码,当我使用
http://stackoverflow.com/
时,它可以正常工作。 When I change it to http://www.sitetest.com/query.php?request=how are you
My app throws an exception. 当我将其更改为
http://www.sitetest.com/query.php?request=how are you
我的应用程序引发异常。 It says: 它说:
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 46: http://www.sitetest.com/query.php?request=how %20are%20you?
What is the Illegal Character in there? 那里的非法字符是什么? I can't spot it.
我没发现
AsyncTask<String, String, String> result = new RequestTask().execute("http://www.sitetest.com/query.php?request=how are you");
try {
this.textToSpeech(result.get().trim());
} catch (InterruptedException e) {
//e.printStackTrace();
Toast.makeText(this, "Interrupted",
Toast.LENGTH_LONG).show();
} catch (ExecutionException e) {
Toast.makeText(this, e.getMessage(),
Toast.LENGTH_LONG).show();
//e.printStackTrace();
}
12-22 19:17:32.547: E/AndroidRuntime(20764): FATAL EXCEPTION: AsyncTask #1 12-22 19:17:32.547: E/AndroidRuntime(20764): java.lang.RuntimeException: An error occured while executing doInBackground() 12-22 19:17:32.547: E/AndroidRuntime(20764): at android.os.AsyncTask$3.done(AsyncTask.java:299) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.FutureTask.run(FutureTask.java:239) 12-22 19:17:32.547: E/AndroidRuntime(20764): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.lang.Thread.run(Thread.java:856) 12-22 19:17:32.547: E/AndroidRuntime(20764): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 46: http://www.sitetest.com/query.php?request=how %20are%20you? 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.net.URI.create(URI.java:727) 12-22 19:17:32.547: E/AndroidRuntime(20764): at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75) 12-22 19:17:32.547: E/AndroidRuntime(20764): at com.sitetest.chat.MainActivity$RequestTask.doInBackground(MainActivity.java:170) 12-22 19:17:32.547: E/AndroidRuntime(20764): at com.sitetest.chat.MainActivity$RequestTask.doInBackground(MainActivity.java:1) 12-22 19:17:32.547: E/AndroidRuntime(20764): at android.os.AsyncTask$2.call(AsyncTask.java:287) 12-22 19:17:32.547: E/AndroidRuntime(20764): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 12-22 19:17:32.547: E/AndroidRuntime(20764): ... 4 more
Seems you have some whitespace character there which is not the regular 似乎那里有一些空白字符,这不是常规字符
space character (decimal 32). 空格字符(十进制32)。 Also, it seems it is not URL encoded.
另外,似乎它不是URL编码的。
You should have inside the execute
sth like: 您应该在
execute
sth之内,例如:
urlencode('http://www.sitetest.com/query.php?request=how are you')
So, complete code on that line: 因此,在该行上完成代码:
AsyncTask<String, String, String> result = new RequestTask().execute(urlencode('http://www.sitetest.com/query.php?request=how are you'));
My source: 我的来源:
PHP URL Encoding / Decoding PHP URL编码/解码
Side note: 边注:
I don't have a php environment installed on my machine right now, the verifying of that function needs to be made by you. 我的机器上现在没有安装php环境,该功能的验证需要您进行。 That's what I found.
那就是我发现的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.