使用URL Java连接到本地主机的错误


 try {
        URL u = new URL("http://[::1]/index.php");
        InputStream in = u.openStream();    
        int b;
        while ((b = in.read()) != -1) {
        System.out.write(b);
        }
       }
        catch (MalformedURLException e) {System.out.println(e);}
        catch (IOException e) {System.out.println(e);}

返回

运行:java.net.connectException:连接拒绝:连接构建 成功(总时间:1秒)

为什么要投掷错误?如何修复它?

您需要在本地主机上运行的服务器并收听端口80,如果没有,您会得到连接拒绝的错误。

最新更新