1

I want to close the get request connection but,it didn't closed.

Its my code block

Edit code block but doesn't work again..

 try {
            HttpClient client = new DefaultHttpClient();
            URI website = website = new URI("http://"+IPAdres+"/?Arduino="+Komut);
            HttpGet request = new HttpGet();
            request.setURI(website);

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            EntityUtils.consume(entity);
            request.abort();
            client.getConnectionManager().shutdown();
            client.getConnectionManager().closeExpiredConnections();

        } catch (URISyntaxException e) {
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        } catch (ClientProtocolException e) {
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        }

I want to close connection after request

Zarzamora
  • 45
  • 1
  • 8

1 Answers1

0

Android ways are little different from java ways. Can yo try this approach?

   URL url = new URL("http://www.android.com/");
   HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
   try {
     InputStream in = new BufferedInputStream(urlConnection.getInputStream());
     readStream(in);
   } finally {
     urlConnection.disconnect();
   }

To read more on this try this link

diyoda_
  • 5,274
  • 8
  • 57
  • 89