Tuesday, July 10, 2012

URL Hitting in android


In android URL hitting mainly use 4-Connection Varibles

  • DefaultHttpClient
  • HttpPost   
  • HttpResponse
  • HttpEntity
             !    DefaultHttpClient  it use to establish the connection between server and android 

                  DefaultHttpClient  varible_name new DefaultHttpClient();      

             !  HttpPost  which is used to communicate the php file(Server) with android.during the http post time varibles\values are posted.

                  HttpPost  varible_name new HttpPost("http://server/projectlocation/phpfile.php?username="+mainusername+"&password="+mainpass);

                  In the above web address username and password are 2 field in php file

               !   HttpResponse this variable used to get the response from the server. Commonly the response in JSON(Java script object notation).


    try
              {
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost("http://projects.jishocom/rahulrk/locAdsLogin.php?username="+mainusername+"&password="+mainpass);

          HttpResponse httpResponse = httpClient.execute(httpPost);
          HttpEntity httpEntity = httpResponse.getEntity();
        String  line = EntityUtils.toString(httpEntity);
           System.out.println("the res"+line);

      } catch (UnsupportedEncodingException e) {
          line = "<results status=\"error\"><msg>Can't connect to serverlllllllll</msg></results>";
     } catch (MalformedURLException e) {
          line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
      } catch (IOException e) {
          line = "<results status=\"error\"><msg>Can't connect to serverjjjjjjjj</msg></results>";
      }


No comments :

Post a Comment