我正在将网站转换为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"}}}
注意:我的登录网址正确执行。但我无法将其会话ID重新用于其他网址。
任何人帮助我?
答案 0 :(得分:1)
我这样做是为了从https网址下载apk文件,你可以根据你的要求进行修改
步骤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
答案 1 :(得分:0)
get3.setHeader("Cookie:","session_id=3dcfe71efba0403ba454cef4d390f1fb");
那应该是
get3.setHeader("Cookie","session_id=3dcfe71efba0403ba454cef4d390f1fb");