Note that there are some explanatory texts on larger screens.

plurals
  1. POAny hints for https form get and post parse html project android?
    primarykey
    data
    text
    <p>I'm creating an Android app that should do the following;</p> <ol> <li>Use a form on a https (SSL!) page to login and receive a cookie</li> <li>Issue httpGET actions to get html</li> <li>parse that html and show it in a view, list or something.</li> </ol> <p>I've been fooling around with Jsoup, httpUnit and HTMLUnit for quite some time now, but I'm running in to several problems;</p> <p>A. Login is fine, works.. (I get the website's welcome page) but then, when I issue a GET statement (and include the cookie), I am redirected to the login form. So the response html is not what I expected. (might have something to do with a keepalivestrategy?)</p> <p>B. InputBuffers are too small to receive entire HTML pages and set them up for parsing.</p> <p>NB : I do not have control over the webserver</p> <p>I'm totally new at this, so a tutorial or code snippets would be helpful.</p> <p>For instance, this is what I use to login to the website :</p> <pre><code>public int checkLogin() throws Exception { ArrayList&lt;NameValuePair&gt; data = new ArrayList&lt;NameValuePair&gt;(); data.add(new BasicNameValuePair("userid", getUsername())); data.add(new BasicNameValuePair("password", getPassword())); data.add(new BasicNameValuePair("submit_login", "Logmein")); Log.d(TAG, "Cookie name : " + getCookieName()); Log.d(TAG, "Cookie cont : " + getCookie()); HttpPost request = new HttpPost(BASE_URL); request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false); request.getParams().setParameter("http.protocol.handle-redirects",false); request.setEntity(new UrlEncodedFormEntity(data, "UTF-8")); HttpResponse response; httpsclient.getCookieStore().clear(); List&lt;Cookie&gt; cookies = httpsclient.getCookieStore().getCookies(); Log.d(TAG, "Number of Cookies pre-login : " + cookies.size()); response = httpsclient.execute(request); cookies = httpsclient.getCookieStore().getCookies(); Log.d(TAG, "Number of Cookies post-login : " + cookies.size()); String html = ""; // Problem : buffer is too small! InputStream in = response.getEntity().getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuilder str = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { str.append(line); } in.close(); html = str.toString(); Document doc = Jsoup.parse(html); Log.v(TAG, "Ik heb nu dit : " + doc.toString()); if (cookies.size() &gt; 0){ storeCookie(cookies.get(0).getName(), cookies.get(0).getValue()); return MensaMobileActivity.REQUEST_SUCCESS; } else { return MensaMobileActivity.REQUEST_ERROR; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload