Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid using cookies with HttpPost and URLconnection
    text
    copied!<p>I'm porting web application to android, and i have a question there. I'm downloading a captcha image from PHP script, and I want to retrieve cookies :</p> <pre><code> Bitmap mIcon11 = null; try { java.net.URL url = new java.net.URL(urldisplay); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setUseCaches(true); connection.connect(); InputStream in = connection.getInputStream(); mIcon11 = BitmapFactory.decodeStream(in); } catch (Exception e) { Log.d("Error", "NEINA SIUSTI IMAGO"); e.printStackTrace(); } </code></pre> <p>and use same cookies in verification here:</p> <pre><code>DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://somesite.lt/index.php"); try { // Add your data List &lt; NameValuePair &gt; nameValuePairs = new ArrayList &lt; NameValuePair &gt; (2); nameValuePairs.add(new BasicNameValuePair("phoneno", ((EditText) findViewById(R.id.number)).getText().toString())); nameValuePairs.add(new BasicNameValuePair("phbody", ((EditText) findViewById(R.id.sms)).getText().toString())); nameValuePairs.add(new BasicNameValuePair("captcha_code", ((EditText) findViewById(R.id.code)).getText().toString())); nameValuePairs.add(new BasicNameValuePair("agree", "on")); nameValuePairs.add(new BasicNameValuePair("submit", "")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); Log.d("ers", "ENtit " + nameValuePairs.toString()); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost, mHttpContext); </code></pre> <p>How can i do it? Retrieve the cookies from URLConnection and use them in that HTTPPost request.</p> <p>Thanks!</p>
 

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