Search code examples
androidhttp-getandroid-internet

passing HTTP GET values in url


i'm trying to send HTTP GET Request with values passed in URL for the site

http://somenthing.com/c/chk.php?val=somevalue

I used the following code but it doesn't seems to work

HttpResponse response = null;
try {        
    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet();
        request.setURI(new URI("http://somenthing.com/c/chk.php?val=somevalue"));
    response = client.execute(request);
    } 
    catch (URISyntaxException e) 
    {        
      e.printStackTrace();
    }
    catch (ClientProtocolException e) 
    {
      e.printStackTrace();
    }
    catch (IOException e) 
    {
      e.printStackTrace();
    }   
    return;

i'm not getting any error, the above code works when the button is pressed and I have used the permission.

Upon receiving the HTTP GET Request the back end process is done by server.


Solution

  • My solution is:

    // ---Connects using HTTP GET---
            public static InputStream OpenHttpGETConnection(String url) {
                InputStream inputStream = null;
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpResponse httpResponse = httpclient.execute(new HttpGet(url));
                    inputStream = httpResponse.getEntity().getContent();
                } catch (Exception e) {
                    Log.d("InputStream", e.getLocalizedMessage());
                }
                return inputStream;
            }