【问题标题】:Session Expired error in SSL HttpClient connectionSSL HttpClient 连接中的会话过期错误
【发布时间】:2015-01-06 08:56:32
【问题描述】:

我正在将网站转换为 Android 应用程序。

相同的代码适用于 http URL,我可以重复使用相同的会话 ID。

但在 https 中我得到会话过期错误。

               HttpPost get3 = new HttpPost(titleURL);
               entity = new StringEntity("{\"jsonrpc\":\"2.0\",\"method\":\"call\",\"params\":{\"model\":\"job.order\",\"fields\":[\"job_code\",\"sale_order_id\",\"partner_id\",\"ins_postcode\",\"client_order_ref\",\"cust_po_ref_blanket\",\"engineer_id\",\"appointment\",\"state\"],\"domain\":[[\"state\",\"=\",[\"draft\",\"confirmed\",\"installed\",\"onhold\",\"reject\",\"accepted\"]]],\"context\":{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"search_default_open_job\":1,\"bin_size\":true},\"offset\":0,\"limit\":80,\"sort\":\"\",\"session_id\":\"3dcfe71efba0403ba454cef4d390f1fb\"},\"id\":\"r105\"}");
               get3.setHeader("Content-Type", "application/json");
               get3.setHeader("Cookie:","session_id=3dcfe71efba0403ba454cef4d390f1fb");
               get3.setEntity(entity);
               trustAll();
               HttpClient client = new DefaultHttpClient();

               responseBody3 = client.execute(get3, responseHandler);

我的 logcat 错误,

提高SessionExpiredException(\"Session expired\")\nSessionExpiredException: Session expired\n", "type": "client_exception"}}}

注意:我的登录 URL 执行正确。但我无法将我的会话 ID 重新用于其他 URL。

有人帮我吗?

【问题讨论】:

    标签: android session ssl https session-cookies


    【解决方案1】:

    我已经这样做了从https url下载apk文件,您可以根据您的要求进行修改

    STEP 1: 建立连接时,在第一个 Activity 中创建 DefaultHttpClient 的实例。

    public static DefaultHttpClient httpClient;
    

    第 2 步:第一次连接

    URL url=new URL(urlToHit);
    LoginScreen.httpClient = new DefaultHttpClient();
    
    HttpPost httppost = new HttpPost(url.toString());
    HttpResponse response = LoginScreen.httpClient.execute(httppost); 
    
    xr.parse(new InputSource(url.openStream()));
    

    第 3 步:现在对于所有进一步的连接,使用相同的 httpClient 例如在下一个活动中:

    URL url=new URL(urlToHit);
    
    HttpPost httppost = new HttpPost(url.toString());
    HttpResponse response = LoginScreen.httpClient.execute(httppost); 
    
    
    HttpEntity entity = response.getEntity();
    
    InputStream instream = null;
    
    if (entity != null) {
    instream = entity.getContent();
    }
    xr.parse(new InputSource(instream)); //SAX parsing
    

    【讨论】:

    • 你在哪里使用会话?我想重新使用我的会话。
    • 我已经为您提供了从任何 HTTPS URL 下载文件。
    • 像链接一样更改您的答案。这个对我有用。如果您更改答案,我会接受。太感谢了。 7 天搜索由您完成。
    【解决方案2】:
    get3.setHeader("Cookie:","session_id=3dcfe71efba0403ba454cef4d390f1fb");
    

    应该是这样的

    get3.setHeader("Cookie","session_id=3dcfe71efba0403ba454cef4d390f1fb");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      • 2011-06-09
      相关资源
      最近更新 更多