点击退出登录的时候发送一个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这部分的代码如下:
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;
}

解决方案 »

  1.   

    LogCat显示抛出的是ClientProtocolException的异常    我该怎么处理啊?   最蛋疼的是这个问题不是每次出现,是有时候才会有
      

  2.   

    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没通过,所以抛出异常。
    后面还有一个这样的空格。
      

  3.   

    这个地址应该是我给服务器发送POST请求后服务器传给客户端的一个地址。。  
      

  4.   

    url 被空格截断了,服务器可能认为参数不合法拒绝连接
    最合理的方法是在服务器端获取登入登出时间,这样避免了客户端时间不一致的问题
    实在不好改的话 客户端对登入登出时间encode一下,服务器收到后decode一下就ok了。