我创建一个服务,通过互联网发布的东西,一切都很好。但是当我将它部署到我们的服务器时,我得到连接状态:403,禁止。我认为这是因为我们的服务器不允许直接访问互联网,而无需先登录。我们必须首先在浏览器中用我们的用户名/密码登录才能访问互联网。在Java中设置代理
我注意到,如果我登录并访问服务器中的互联网,我部署的服务运行正常。但我不认为这很实际,因为在那种情况下,如果有人或我不先登录,我的服务将无法运行。
我曾尝试在java代码中设置代理,但无济于事。有人可以帮我解决这个问题吗?这里是我张贴我的服务片段。
System.getProperties().put("http.proxySet", "true");
System.getProperties().put("http.proxyHost", myHost);
System.getProperties().put("http.proxyPort", "8080");
System.getProperties().put("http.proxyUser", myUser);
System.getProperties().put("http.proxyPassword", myPassword);
System.getProperties().put("http.nonProxyHosts", "localhost|127.0.0.1");
try {
URL url = new URL(urlAddress);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
...
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
System.out.println("connection OK");
istrm = con.getInputStream();
if (istrm == null) {
System.out.println("istrm == null");
}
...
} else {
System.out.println("Response: " + con.getResponseCode() + ", " + con.getResponseMessage());
}
}
而我处理转到别的块,并得到响应消息403
http.proxySet是一个城市神话。它没有效果。 – EJP 2012-04-11 18:59:44