varuog
varuog

Reputation: 3081

Error in connecting to localhost using 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);}

returns

run: java.net.ConnectException: Connection refused: connect BUILD SUCCESSFUL (total time: 1 second)

Why it is throwing error? how to fix it?

Upvotes: 0

Views: 1146

Answers (1)

burna
burna

Reputation: 2962

You need a server running on your localhost and listening to port 80, if not you get the connection refused error..

Upvotes: 2

Related Questions