我一直在试图访问一个网站,为Android应用程序,我发展分析数据,但我有没有运气,当谈到在记录登录后解析HTML源。与Java
的网站
<form action="/mobile/login" method="post">
<input type="hidden" name="login_security_token" value="b22155c7259f402f8e005a771c460670">
<input type="hidden" name="redirect" value="/mobile">
<input type="hidden" name="p_next_page" value="">
<input name="nickname" maxlength="25" type="text" value="" />
<input name="password" type="password" value="" />
<button name="step" type="submit" value="Login">Login</button>
</form>
任何人都可以请建议我如何使用Java然后解析重定向页面登录到这个网站:https://giffgaff.com/mobile/login
而下方则是从该网页(HTML)剥离出来的形式的版本?
到现在为止,我已经试过上的线流程:
public static void main(Context context) {
try {
// Construct data
String data = URLEncoder.encode("nickname", "UTF-8") + "=" + URLEncoder.encode("testingA", "UTF-8");
data += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode("testing", "UTF-8");
// Send data
URL url = new URL("https://giffgaff.com/mobile/login");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str = "";
String line;
while ((line = rd.readLine()) != null) {
str += line;
}
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Output");
alertDialog.setMessage(str);
alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
wr.close();
rd.close();
} catch (Exception e) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("ERROR");
alertDialog.setMessage(e.toString());
alertDialog.setButton("Okay", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
但我尝试返回页面如果登录信息是不正确的。
如果你想看到自己的登录页面的行为,这里的一些测试登录详细信息: 昵称(用户名):testingA 密码:测试 该网站还似乎依赖于一个名为“napaSessionId”
曲奇