【发布时间】:2011-03-16 02:14:36
【问题描述】:
我创建了一个通过互联网发布内容的服务,一切都很好。但是当我将它部署到我们的服务器时,我得到连接状态:403,禁止。我认为这是因为我们的服务器不允许在没有先登录的情况下直接访问互联网。我们必须先使用我们的用户名/密码在浏览器中登录才能访问互联网。
我注意到,如果我在服务器中登录并访问互联网,我部署的服务运行正常。但我认为这不实用,因为在这种情况下,如果有人或我不先登录,我的服务将无法运行。
我尝试在 java 代码中设置代理,但无济于事。有人可以帮我解决这个问题吗?这是我发布我的服务 sn-p。
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());
}
}
我的进程进入 else 块并获得响应消息 403
【问题讨论】:
-
http.proxySet 是一个都市神话。它没有效果。