点击退出登录的时候发送一个POST请求来退出登录,但是有时候(不是每次)会出现下面的情况(LogCat):
我该怎么写才能获取这个Invalid redirect URI呢?
10-12 20:34:12.586: W/System.err(6515): org.apache.http.client.ClientProtocolException
10-12 20:34:12.586: W/System.err(6515): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
10-12 20:34:12.590: W/System.err(6515): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
10-12 20:34:12.590: W/System.err(6515): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
10-12 20:34:12.590: W/System.err(6515): at com.mysoft.login4u.HttpPostService.sendPostRequest(HttpPostService.java:92)
10-12 20:34:12.590: W/System.err(6515): at com.mysoft.login4u.Logined$1$1.run(Logined.java:42)
10-12 20:34:12.590: W/System.err(6515): Caused by: org.apache.http.ProtocolException: Invalid redirect URI: http://202.202.96.57:9030?action=22&login_time=2012-10-12 18:27:39&logout_time=2012-10-12 20:34:11&money2=0.0
10-12 20:34:12.590: W/System.err(6515): at org.apache.http.impl.client.DefaultRedirectHandler.getLocationURI(DefaultRedirectHandler.java:116)
10-12 20:34:12.590: W/System.err(6515): at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:923)
10-12 20:34:12.593: W/System.err(6515): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:475)
10-12 20:34:12.593: W/System.err(6515): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
10-12 20:34:12.593: W/System.err(6515): ... 4 more
10-12 20:34:12.593: W/System.err(6515): Caused by: java.net.URISyntaxException: Illegal character in query at index 57: http://202.202.96.57:9030?action=22&login_time=2012-10-12 18:27:39&logout_time=2012-10-12 20:34:11&money2=0.0
10-12 20:34:12.593: W/System.err(6515): at libcore.net.UriCodec.validate(UriCodec.java:63)
10-12 20:34:12.593: W/System.err(6515): at java.net.URI.parseURI(URI.java:406)
10-12 20:34:12.593: W/System.err(6515): at java.net.URI.<init>(URI.java:204)
10-12 20:34:12.597: W/System.err(6515): at org.apache.http.impl.client.DefaultRedirectHandler.getLocationURI(DefaultRedirectHandler.java:114)
10-12 20:34:12.597: W/System.err(6515): ... 7 more
这部分的代码如下:
- Java code
public static boolean sendPostRequest() { HttpPost httpRequest = new HttpPost(loginURL_2); try { HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); if (httpResponse.getStatusLine().getStatusCode() == 200) { return true; } else { Log.d("error", "Error Response: " + httpResponse.getStatusLine().toString()); } } catch (ClientProtocolException e) { Log.d("ex", "1"); e.printStackTrace(); } catch (IOException e) { Log.d("ex", "2"); e.printStackTrace(); } catch (IllegalStateException e) { Log.d("ex", "3"); e.printStackTrace(); } catch (Exception e) { Log.d("ex", "4"); e.printStackTrace(); } return false; }
------解决方案--------------------
10-12 20:34:12.593: W/System.err(6515): Caused by: java.net.URISyntaxException: Illegal character in query at index 57:
http://202.202.96.57:9030?action=22&login_time=2012-10-12 18:27:39&logout_time=2012-10-12 20:34:11&money2=0.0
uri中index 57的位置是字符串“2012-10-12 18:27:39”中日期12后的空格,检查uri没通过,所以抛出异常。
后面还有一个这样的空格。
------解决方案--------------------