这是我正在使用打开 URLConnection 到另一个 webapllication 的代码
try {
URL url = new URL("https://mySecondWebApp/Cart");
HttpsURLConnection conn1 = (HttpsURLConnection) url.openConnection();//line1
conn1 .connect();//line 2 does not establishes the connection
conn1.getInputStream();// line 3 works which means that i get control to my app2 in debugger.But this also passes the control to IOException stating error java.io.FileNotFoundException: https://mySecondWebApp/Cart
}
catch (MalformedURLException e) {
log.error("MalformedURLException" + e);
}
catch (IOException e) {
log.info("getting IO error");
}
我不明白为什么第 2 行没有与 app2 建立连接,而第 3 行没有?第二件事是为什么我在第 3 行之后得到文件 notfound 异常,即使它成功连接到我想避免的 app2。我的目的只是建立与 app2 的连接,以便我在 app2 的 java 代码中获得控制权