我想关闭get请求连接,但它没有关闭。
这是我的代码块
编辑代码块但不能再次工作..
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();
}我想在请求后关闭连接
发布于 2017-04-28 05:27:24
Android的方式与java的方式稍有不同。你能试试这种方法吗?
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();
}阅读有关此try this link的更多信息
https://stackoverflow.com/questions/43668102
复制相似问题