【发布时间】:2014-02-04 19:51:43
【问题描述】:
我使用简单的代码来获取http://www.ip-adress.com 的 html,但它显示错误 http 代码 403。 我在程序中的其他网站(如google.com)中尝试它,它可以工作。我也可以在浏览中打开www.ip-adress.com,为什么我不能在java程序中使用它。
public class urlconnection
{
public static void main(String[] args)
{
StringBuffer document = new StringBuffer();
try
{
URL url = new URL("http://www.ip-adress.com");
URLConnection conn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null)
document.append(line + " ");
reader.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
System.out.println(document.toString());
}
}
java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.ip-adress.com/
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at urlconnection.main(urlconnection.java:14)
【问题讨论】:
-
你检查你的代理配置了吗?
-
你搜索过 403 是什么意思吗?
标签: java http http-headers