Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Httpsurlconnection没有';不要合上插座_Java_Android - Fatal编程技术网

Java Httpsurlconnection没有';不要合上插座

Java Httpsurlconnection没有';不要合上插座,java,android,Java,Android,我试图解决这个问题,但没有找到一个好的解决方案。 我刚刚打开了一个带有httsurl连接的插座,然后关闭了。 但是,我打开的套接字没有关闭,并且套接字状态为close\u WAIT。 这是我的代码和飞行日志。 我的代码有什么问题 String https_url = "https://www.google.com"; URL url = new URL(https_url); try { con = (HttpsURLConnection) url.o

我试图解决这个问题,但没有找到一个好的解决方案。 我刚刚打开了一个带有httsurl连接的插座,然后关闭了。 但是,我打开的套接字没有关闭,并且套接字状态为close\u WAIT。 这是我的代码和飞行日志。 我的代码有什么问题

    String https_url = "https://www.google.com";

    URL url = new URL(https_url);

    try {
        con = (HttpsURLConnection) url.openConnection();
        con.setRequestProperty("Connection", "close");
        if(con!=null){
            BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String input = br.readLine();
            while(input.length() != 0)
            {

                input = br.readLine();  
            }
            br.close();
            con.disconnect();               

        }
    }
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

您肯定从这段代码中得到了NullPointerException。在执行任何其他操作之前,必须测试readLine()的结果是否为null。我不明白在HTML页面中测试空行有什么意义。

谢谢你的建议。:)虽然我测试了这段代码,但也没有例外。你说得对。我将添加一些用于检查null异常的代码。此代码的目的是使用httpsurlconnection函数通过ssl进行连接。