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

Apps Not able to login to website through my application

i am trying to connect to VidyalankarLive.com

and the login page is Vidyalankar Live

the problem is that when i click the login button it tries to connect and in response i just get the login page back.
I am not able to figure out what the problem i actually.

code
CoustomHttpClient.java
Code:
    package com.example.login;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.URI;
    import java.util.ArrayList;

    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.conn.params.ConnManagerParams;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.params.HttpConnectionParams;
    import org.apache.http.params.HttpParams;

    public class CustomHttpClient {   
        public static final int HTTP_TIMEOUT = 30 * 1000; // milliseconds

        private static HttpClient getHttpClient() {
            if (mHttpClient == null) {
                mHttpClient = new DefaultHttpClient();
                final HttpParams params = mHttpClient.getParams();
                HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
                HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
                ConnManagerParams.setTimeout(params, HTTP_TIMEOUT);
            }
            return mHttpClient;
        }

          public static String executeHttpPost(String url, ArrayList<NameValuePair> postParameters) throws Exception {
            BufferedReader in = null;
            try {
                HttpClient client = getHttpClient();
                HttpPost request = new HttpPost(url);
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
                request.setEntity(formEntity);
                HttpResponse response = client.execute(request);
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();

                String result = sb.toString();
                return result;
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

          public static String executeHttpGet(String url) throws Exception {
            BufferedReader in = null;
            try {
                HttpClient client = getHttpClient();
                HttpGet request = new HttpGet();
                request.setURI(new URI(url));
                HttpResponse response = client.execute(request);
                in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

                StringBuffer sb = new StringBuffer("");
                String line = "";
                String NL = System.getProperty("line.separator");
                while ((line = in.readLine()) != null) {
                    sb.append(line + NL);
                }
                in.close();

                String result = sb.toString();
                return result;
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

LoginLayout.java
Code:
    package com.example.login;

    import java.util.ArrayList;

    import org.apache.http.NameValuePair;
    import org.apache.http.message.BasicNameValuePair;

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

    public class LoginLayout extends Activity {
        EditText un,pw;
       TextView error;
        Button ok;
       
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            un=(EditText)findViewById(R.id.et_un);
            pw=(EditText)findViewById(R.id.et_pw);
            ok=(Button)findViewById(R.id.btn_login);
            error=(TextView)findViewById(R.id.tv_error);

            ok.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                   

                   ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                   postParameters.add(new BasicNameValuePair("vb_text_username", un.getText().toString()));
                   postParameters.add(new BasicNameValuePair("vb_text_password", pw.getText().toString()));

                   String response = null;
                   try {
                       response = CustomHttpClient.executeHttpPost("http://www.vidyalankarlive.com/site/login.php", postParameters);
                       String res=response.toString();
                      
                       /*i am guessing that there must be some problem in here cause the website dosent have response for 1 or 0
                        but at least when i print the res it must show me the logged in info right?? */
                       if(res.equals("1"))
                          error.setText("Correct Username or Password");
                       else
                          error.setText("Sorry!! Incorrect Username or Password");
                   } catch (Exception e) {
                      un.setText(e.toString());
                   }

                }
            });
        }
    }

main.xml
Code:
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dip"
        android:background="#DDDDDD">
        <TextView
            android:id="@+id/tv_un"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10pt"
            android:textColor="#444444"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="9dip"
            android:layout_marginTop="20dip"
            android:layout_marginLeft="10dip"
            android:text="User Name:"/>
        <EditText
            android:id="@+id/et_un"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background"
            android:layout_toRightOf="@id/tv_un"
            android:layout_alignTop="@id/tv_un" android:text="@string/jugaldesai"/>
         <TextView
            android:id="@+id/tv_pw"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10pt"
            android:textColor="#444444"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/tv_un"
            android:layout_marginRight="9dip"
            android:layout_marginTop="15dip"
            android:layout_marginLeft="10dip"
            android:text="Password:"/>
        <EditText
            android:id="@+id/et_pw"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:background="@android:drawable/editbox_background"
            android:layout_toRightOf="@id/tv_pw"
            android:layout_alignTop="@id/tv_pw"
            android:layout_below="@id/et_un"
            android:layout_marginLeft="17dip"
            android:password="true"        android:text="@string/jacky123"/>
        <Button
            android:id="@+id/btn_login"
            android:layout_width="100dip"
            android:layout_height="wrap_content"
            android:layout_below="@id/et_pw"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="15dip"
            android:layout_marginLeft="110dip"
            android:text="Login" />
         <TextView
            android:id="@+id/tv_error"
            android:layout_width="fill_parent"
            android:layout_height="40dip"
            android:textSize="7pt"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/btn_login"
            android:layout_marginRight="9dip"
            android:layout_marginTop="15dip"
            android:layout_marginLeft="15dip"
            android:textColor="#AA0000"
            android:text=""/>
    </RelativeLayout>
 
Back
Top Bottom