tags:

views:

24

answers:

0

i am a new android and not much familiar with all the libraries. i am trying to acces a simple web page(google.com) through my android app. i have made the http requst but i am not able to see anything after i click the button

public void onClick (View viewParam)
      {
       EditText usernameEditText = (EditText) findViewById(R.id.txtuser);
       EditText passwordEditText = (EditText) findViewById(R.id.txtpass);
       String aUserName = usernameEditText.getText().toString();
       String aPassword = passwordEditText.getText().toString();

       if(aUserName.length() == 0 || aPassword.length() == 0){
        //Toast.makeText(getApplicationContext(),"Not Found",Toast.LENGTH_SHORT).show();
       }
       else{
        Toast.makeText(getApplicationContext(),"Username: " + aUserName + "Password: " + aPassword ,Toast.LENGTH_SHORT).show();
        String URL = "http://www.google.com/";
        HttpClient httpclient = new DefaultHttpClient();
        try {
     HttpResponse response = httpclient.execute(new HttpGet(URL));
     StatusLine statusLine = response.getStatusLine();
     if(statusLine.getStatusCode() >1){
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            response.getEntity().writeTo(out);
            out.close();
            String responseString = out.toString();
            //..more logic
        }
     else{
            //Closes the connection.
            response.getEntity().getContent().close();
            throw new IOException(statusLine.getReasonPhrase());
        }
    } catch (ClientProtocolException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }