まず、これをブラウザで行うか、コードで行うかを決定する必要があります。
コードでは、おそらく次のような HTTP 投稿を自動化する必要があります。
// Start up your network connection
URL url = new URL("http://www.asdf.com/someFormSubmissionPage);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
String userInfo = "username=bob&password=pass";
connection.setRequestProperty("Content-Length", "" + userInfo.length());
connection.setDoOutput(true);
// Send the actual data
OutputStream out = connection.getOutputStream();
out.write(userInfo.getBytes(UTF_8));
// Flush everything to the destination
out.flush();
out.close();
BufferedReader connectionReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), UTF_8));
String responseLine;
// Collect the entire response
while ((responseLine = connectionReader.readLine()) != null)
response.append(responseLine);
この時点で、応答で何かを行うことができます。おそらく、サーバーが返信する Cookie を保存するか、必要に応じて何でもできます。
別の方法として、WebView を開いて次のようなアドレスを指定することもできます。http://www.asdf.com/someFormSubmissionPage?username=bob&password=pass
これにより、ユーザーがログインした状態でブラウザーが起動します。
これは、実際のサイトのログイン ページを見ながらブラウザでsomeFormSubmissionPage
実行するとわかります。view source
ユーザー名/パスの詳細もこの方法で見つけることができます。