java .net。 ConnectException:连接被拒绝

时间:2017-05-10 07:26:40

标签: java http

  1. 我试图拨打http电话,如果我设置" localost:8090"在我的网址中 代码工作     如果我设置外部IP代码不起作用。

    java.net.ConnectException: Connection refused: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
    
  2. 代码就是这个

       URL url = new URL("http://www.searchinquire.com/");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    
                BufferedReader br = new BufferedReader(new InputStreamReader(
                    (conn.getInputStream())));
    
                String output;
                System.out.println("Output from Server .... \n");
                while ((output = br.readLine()) != null) {
                    System.out.println(output);
                }
    
                conn.disconnect();
    
              } catch (MalformedURLException e) {
    
                e.printStackTrace();
    
              } catch (IOException e) {
    
                e.printStackTrace();
    
              }
    

0 个答案:

没有答案