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

Apps Android application PHP website login

Is there anyway i could login on a remote site using my app? Not PHP ^^

it's just a normal https html login form

this is what i have now

package com.danielholst.lectio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Login extends Activity implements OnClickListener {

Button ok,back,exit;
TextView result;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);

// Login button clicked
ok = (Button)findViewById(R.id.btn_login);
ok.setOnClickListener(this);

result = (TextView)findViewById(R.id.tv_error);

}

public void postLoginData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();

/* login.php returns true if username and password is equal to saranga */
HttpPost httppost = new HttpPost("https://www.lectio.dk/lectio/92/login.aspx");

try {
// Add user name and password
EditText uname = (EditText)findViewById(R.id.et_un);
String username = uname.getText().toString();

EditText pword = (EditText)findViewById(R.id.et_pw);
String password = pword.getText().toString();

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("m_Content_username2", username));
nameValuePairs.add(new BasicNameValuePair("m_Content_password2", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
Log.w("SENCIDE", "Execute HTTP Post Request");
HttpResponse response = httpclient.execute(httppost);

String str = inputStreamToString(response.getEntity().getContent()).toString();
Log.w("SENCIDE", str);

if(str.toString().equalsIgnoreCase("true"))
{
Log.w("SENCIDE", "TRUE");
result.setText("Loading ...");
}else
{
Log.w("SENCIDE", "FALSE");
result.setText("Login Fejl");
}

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// Return full string
return total;
}

public void onClick(View view) {
if(view == ok){
postLoginData();
}
}

}

as you can see, i'm trying to access https://www.lectio.dk/lectio/92/login.aspx
 
Back
Top Bottom