Just in case, someone else had a problem, I had a similar problem, and I was able to solve it using the following code:
1- Define CookieManager and CookieStore in your class
CookieManager cookieManager; CookieStore cookieStore;
2- Add a default cookie handler, for example. in the class constructor or in the OnCreate method
cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager);
3- Use cookie storage when you execute an HTTP request
public byte[] openURI(String uri) { try { URI uriObj = new URI(uri); DefaultHttpClient client = new DefaultHttpClient(); // Use the cookieStor with the request if (cookieStore == null) { cookieStore = client.getCookieStore(); } else { client.setCookieStore(cookieStore); } HttpGet getRequest = new HttpGet(uriObj); HttpResponse response = client.execute(getRequest); // Read the response data InputStream instream = response.getEntity().getContent(); int contentLength = (int) response.getEntity().getContentLength(); byte[] data = new byte[contentLength]; instream.read(data); response.getEntity().consumeContent(); return data ; } catch (URISyntaxException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
iTech source share