Rest 获取具有端口号的url的https连接
我正在编写一个代码,用于从包含端口号(而不是80)的url获取信息。这是我的代码,我收到一个错误HTTPS主机名错误:应该位于openconnection。我可以获得解决方案吗。 谢谢Rest 获取具有端口号的url的https连接,rest,Rest,我正在编写一个代码,用于从包含端口号(而不是80)的url获取信息。这是我的代码,我收到一个错误HTTPS主机名错误:应该位于openconnection。我可以获得解决方案吗。 谢谢 HttpsURLConnection connection_ = null; URL url = new URL("https://localhost:9080/xyz"); connection_ = (HttpsURLConnection) url.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();
}