Web アプリケーションを Android に移植していますが、そこで質問があります。PHP スクリプトからキャプチャ イメージをダウンロードしており、Cookie を取得したい:
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();
}
ここで検証に同じCookieを使用します。
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://somesite.lt/index.php");
try {
// Add your data
List < NameValuePair > nameValuePairs = new ArrayList < NameValuePair > (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);
どうすればできますか?URLConnection から Cookie を取得し、その HTTPPost 要求で使用します。
ありがとう!