Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Problems with consecutive HttpPosts
    primarykey
    data
    text
    <p>I'm writing a simple HttpClient in Android because I need to make various POST requests in succession. I first do a HttpGet and than the fisrt HttpPost. I can retrieve the HTML of the first GET and of the first POST. But if I do a new GET or a new POST I obtain a blank response. To clarify my problem I attach the code.</p> <pre><code> DefaultHttpClient httpclient = new DefaultHttpClient(); //FIRST GET TO ACCESS LOGIN MODULE try { HttpGet httpget = new HttpGet("https://site/link_to_access_the_login_form"); HttpResponse response = null; try { response = httpclient.execute(httpget); } catch (ClientProtocolException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } HttpEntity entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); entity.consumeContent(); //FIRST POST TO ACCESS THE RESTRICTED AREA HttpPost httpost = new HttpPost("https://site/login/login.do"); List &lt;NameValuePair&gt; nameValuePairs = new ArrayList &lt;NameValuePair&gt;(6); nameValuePairs.add(new BasicNameValuePair("login", "uid")); nameValuePairs.add(new BasicNameValuePair("password", "pwd")); //additional params httpost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); try { response = httpclient.execute(httpost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); //entity.consumeContent(); try { String responseTextPost1 = EntityUtils.toString(entity); entity.consumeContent(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //SECOND POST TO ACCESS A LINK IN THE RESTRICTED AREA httpost = new HttpPost("https://site/role/script.do"); List &lt;NameValuePair&gt; nameValuePairs6 = new ArrayList &lt;NameValuePair&gt;(6); //Parameters... httpost.setEntity(new UrlEncodedFormEntity(nameValuePairs6, HTTP.UTF_8)); try { response = httpclient.execute(httpost); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Login form get: " + response.getStatusLine()); entity = response.getEntity(); try { String responseTextPost2 = EntityUtils.toString(entity); entity.consumeContent(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch.............. </code></pre> <p><strong>responseTextPost2</strong> seems to be blank. Suggestions on how to manage this problem?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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