【问题标题】:Getting Network is unreachable on IPV6 Network在 IPV6 网络上无法访问网络
【发布时间】:2016-07-07 11:00:21
【问题描述】:

我从任何 url 的 Java Http 请求下方得到“网络无法访问”。

下面的代码在 IPV4 网络上运行良好。

                       HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                       conn.setRequestMethod("GET");
                       conn.setDoOutput(true);
                       conn.setRequestProperty("Accept", "application/json");

                       if (conn.getResponseCode() != 200) {
                               throw new RuntimeException("Failed : HTTP error code : "
                                               + conn.getResponseCode());
                       }

                       BufferedReader br = new BufferedReader(new InputStreamReader(
                               (conn.getInputStream())));


                       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();

                 }

请帮我解决这个问题。

【问题讨论】:

  • Java IPv6 支持中存在一个错误,JDK-8015415。尝试升级您的 JRE。
  • 有人找到答案了吗?

标签: java ipv6 httpconnection oracle-maf


【解决方案1】:

如果您使用 IP 地址指定 IPv6 URL,则需要将其括在方括号中,因为地址中的 :: 是 URL 中的特殊字符。

RFC 2732

【讨论】:

  • 如果这是问题所在,OP 会收到 UnknownHostException,而不是“无法访问网络”
猜你喜欢
  • 1970-01-01
  • 2017-04-16
  • 1970-01-01
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 2014-01-29
  • 2017-10-30
  • 1970-01-01
相关资源
最近更新 更多