I want to try to check my login program with Jsoup in Android Studio. But Something is wrong. At first I'm login with "Connection.Response". and then after login I get information and put it to element. but when i check with "if" it is not working. How can i check if login was successful? please help me.
this is my code
public class MainActivity extends Activity {
Button b1, b2;
EditText ed1, ed2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
ed1 = (EditText) findViewById(R.id.editText);
ed2 = (EditText) findViewById(R.id.editText2);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String cheak = null;
Connection.Response response;
try {
response = Jsoup.connect("https://ecampus.smu.ac.kr/login/index.php")
.data("username", ed1.getText().toString(), "password", ed2.getText().toString())
.method(Connection.Method.GET)
.timeout(1000)
.execute();
Document doc = Jsoup.connect("http://ecampus.smu.ac.kr/").cookies(response.cookies()).get();
Elements element = doc.select(".course_subject");
cheak = element.toString();
if (cheak != null) {
Toast.makeText(getApplicationContext(),
"Username and password is correct", Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, Next.class));
} else {
Toast.makeText(getApplicationContext(),
"Username and password is NOT correct", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}