1

I am working with converting website into android app.

Same code work for http URL & I can Re-use same Session id.

But in https I get session expired error.

               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);

My logcat error,

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

Note: My login URL executes correctly.But I cannot re-use my session id for other URL`s.

any body help me?

stacktry
  • 324
  • 3
  • 24

2 Answers2

1

I have done this for downloading apk file from https url, you can modify according to your requirement

STEP 1: Created an instance of DefaultHttpClient in the first Activity when connection established.

public static DefaultHttpClient httpClient;

STEP 2: For the first time connection

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()));

STEP 3: Now for all further connections, used the same httpClient For example in the next activity:

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
Vibhor Chopra
  • 647
  • 4
  • 14
0
get3.setHeader("Cookie:","session_id=3dcfe71efba0403ba454cef4d390f1fb");

That should be

get3.setHeader("Cookie","session_id=3dcfe71efba0403ba454cef4d390f1fb");
user207421
  • 305,947
  • 44
  • 307
  • 483