我正在尝试连接到weblogic 10.3.6上部署的应用程序中的REST API。独立运行时,示例代码工作正常(weblogic服务器外)。但是,当我部署相同的代码时,它开始给我这个错误
无法与代理通信:proxy.xxx.xxx/xxxx。现在尝试连接api.forecast.io/443。 weblogic.net.http.HttpUnauthorizedException:需要代理或服务器身份验证 在weblogic.net.http.HttpURLConnection.getAuthInfo(HttpURLConnection.java:297) 在weblogic.net.http.HttpsClient.makeConnectionUsingProxy(HttpsClient.java:440) 在weblogic.net.http.HttpsClient.openServer(HttpsClient.java:351) 在weblogic.net.http.HttpsClient.New(HttpsClient.java:527) 在weblogic.net.http.HttpsURLConnection.connect(HttpsURLConnection.java:239)
我们正在运行的代码如下
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[] { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
} }, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
} catch (Exception e) { // should never happen
e.printStackTrace();
}
try {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy.xxxx.xxxx", xxxx));
URL url = new URL("https://api.forecast.io/forecast/xxxxxxxxx/12.9667,77.5667");
HttpURLConnection conn = (HttpURLConnection)url.openConnection(proxy);
conn.setRequestMethod("GET");
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())));
String output;
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();
}
return "";
我们的代理是公司代理,没有任何用户名/密码。我们现在已经坚持这个问题了。任何建议/指示都将非常感激。