使用HttpURLConnection是必要的,使用disconnect()

时间:2016-05-04 11:10:43

标签: httpurlconnection

如果我在使用HttpURLConnection时不使用disconnect(),可以请任何人解释会有什么影响。我通过连接发送和接收数据。并关闭输入和输出流。这还不够,或者我应该明确地使用disconnect()。

        URL url = new URL(urlname);
        HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection();
        urlconnection.setRequestMethod("POST");             
        urlconnection.setDoOutput(true);
        urlconnection.setConnectTimeout(s_time);
        OutputStreamWriter out = new OutputStreamWriter(urlconnection.getOutputStream());
        out.write(postData);
        out.close();
        BufferedReader in = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
        String somestring;
        while ((somestring = in.readLine()) != null) {
            data += somestring;
        }
        in.close();

0 个答案:

没有答案