• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Logging into a website

OllyHal

Lurker
Hi,

I am a complete beginner at this HTTP stuff so bear with me! I have looked around for tutorials and example code to try and help me log in to an online banking system. Here is my code. I believe I may have to add some auth code in the header or some more parameters. Any help would be much appreciated!

[HIGH]public class PostData extends AsyncTask<Void, String, Boolean> {
Context ourContext;

public PostData(Context c) {
ourContext = c;
}

@Override
protected Boolean doInBackground(Void... arg0) {


HttpPost httppost = new HttpPost(
"https://online.lloydstsb.co.uk/personal/logon/login.jsp?WT.ac=hpIBlogon");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("frmLogin:strCustomerLogin_userID", "<myuser>"));
nameValuePairs.add(new BasicNameValuePair("frmLogin:strCustomerLogin_pwd", "<mypass>"));
nameValuePairs.add(new BasicNameValuePair("frmLogin:btnLogin1", "Continue"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
HttpResponse response = getClient().execute(httppost);
try {


if(response.getStatusLine().getStatusCode() == 200) {

HttpEntity entity = response.getEntity();
System.out.println("Success");



} else {
System.out.println("ERROR");
}

} catch (Exception e) {

}


} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}

public DefaultHttpClient getClient() {
DefaultHttpClient ret = null;

// sets up parameters
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "utf-8");
params.setBooleanParameter("http.protocol.expect-continue", false);

// registers schemes for both http and https
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
final SSLSocketFactory sslSocketFactory = SSLSocketFactory
.getSocketFactory();
sslSocketFactory
.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));

ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(
params, registry);
ret = new DefaultHttpClient(manager, params);
return ret;
}

}
[/HIGH]

It will always return 200 for me no matter what the username and password is! so I do not think the page is being executed properly!
 
Solved the problem, I just had to find out all the tokens and variables being passed! PM me if anyone needs help with this.
 
Back
Top Bottom