0
 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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.