获取具有端口号的URL的https连接

时间:2012-10-08 11:39:53

标签: rest

我正在编写一个代码,用于从包含80以外的端口号的URL获取信息。这是我的代码,我收到错误HTTPS主机名错误:应该在openconnection.Can我得到一个解决方案。 三江源。

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


}

0 个答案:

没有答案
相关问题