SessionExpiredException错误的Android JSON

SessionExpiredException错误的Android JSON

问题描述:

在Android的RESTful Web服务,SessionExpiredException错误的Android JSON

  1. HttpClient client = new DefaultHttpClient(); - 我获得成功的响应。

  2. 但是现在我的URL已更改为http到https(SSL)。 - 而这个URL不可信证书。

因此我使用以下@Daniel代码。

Trusting all certificates using HttpClient over HTTPS

  1. 如果我使用client = WebClientDevWrapper.getNewHttpClient();而不是DefaultClient() - 我得到sessionExpiredException错误。
  2. 任何帮助?

开始=>

我希望你用这种方法

public void connect() throws Exception { 

     HttpPost post = new HttpPost(new URI("")); 
     post.setEntity(new StringEntity("")); 
     trustAll(); 
     HttpClient client = new DefaultHttpClient(); 
     HttpResponse result = client.execute(post); 
    } 

的HttpsURLConnection的前添加该代码,它会做。

private void trustAll() { 
    try { 
      HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){ 
        public boolean verify(String hostname, SSLSession session) { 
          return true; 
        }}); 
      SSLContext context = SSLContext.getInstance("TLS"); 
      context.init(null, new X509TrustManager[]{new X509TrustManager(){ 
        public void checkClientTrusted(X509Certificate[] chain, 
            String authType) throws CertificateException {} 
        public void checkServerTrusted(X509Certificate[] chain, 
            String authType) throws CertificateException {} 
        public X509Certificate[] getAcceptedIssuers() { 
          return new X509Certificate[0]; 
        }}}, new SecureRandom()); 
      HttpsURLConnection.setDefaultSSLSocketFactory( 
          context.getSocketFactory()); 
    } catch (Exception e) { 
      Log.e("TAG",e); 
    } 
} 

此方法适用于我接受证书并尝试增加会话超时。

+0

先尝试一下,然后尝试传递主机名和布尔值,这为我工作。 – Piyush 2014-11-09 12:40:31

+0

您的代码适用于登录页面网址。但是我在主页面URL中获得会话过期。我使用相同的会话ID。 – stacktry 2014-11-09 13:33:56

+0

好的,但是你的网址会在我身边工作吗? – Piyush 2014-11-09 13:56:06