1

我正在编写一个代码,用于从包含 80 以外的端口号的 url 获取信息。这是我的代码,我收到一个错误 HTTPS hostname wrong: should be at openconnection。我能得到解决方案吗?谢谢你。

HttpsURLConnection connection_ = null;  


    URL url = new URL("https://localhost:9080/xyz");

    connection_ = (HttpsURLConnection) url.openConnection();
    if (connection_ != null) {
        connection_.disconnect();
    }

 if (connection_.getResponseCode() != 200) {
    throw new IOException(connection_.getResponseMessage());
  }
  // Buffer the result into a string
  BufferedReader rd = new BufferedReader(
      new InputStreamReader(connection_.getInputStream()));
  StringBuilder sb = new StringBuilder();
  String line;
  while ((line = rd.readLine()) != null) {
    sb.append(line);
  }
  System.out.println(sb.toString());
  rd.close();

  connection_.disconnect();


}
4

0 回答 0