【发布时间】:2015-07-07 10:06:39
【问题描述】:
我尝试在我的 java 程序中访问 this url,但我收到了这条奇怪的消息,而不是我所期望的页面内容。
我怎样才能避免这种情况?
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>303 See Other</title>
</head>
<body>
<h1>See Other</h1>
<p>The answer to your request is located <a href="https://www.wikidata.org/wiki/Special:EntityData/P26">here</a>.</p>
</body>
</html>
虽然我可以在浏览器中轻松导航。是否有一些函数或库可以用来从我的 java 程序中调用该功能?
for (String url : list_of_relation_URLs)
{
//System.out.println( url );
//go to relation url
String URL_czech = url;
System.out.println( url );
URL wikidata_page = new URL(URL_czech);
HttpURLConnection wiki_connection = (HttpURLConnection)wikidata_page.openConnection();
InputStream wikiInputStream = null;
try
{
// try to connect and use the input stream
wiki_connection.connect();
wikiInputStream = wiki_connection.getInputStream();
}
catch(IOException error)
{
// failed, try using the error stream
wikiInputStream = wiki_connection.getErrorStream();
}
// parse the input stream using Jsoup
Document docx = Jsoup.parse(wikiInputStream, null, wikidata_page.getProtocol()+"://"+wikidata_page.getHost()+"/");
System.out.println( docx.toString() );
}
我正在尝试做与what is going on here 基本相反的事情。
【问题讨论】:
-
这是一个重定向。看看你得到的 http 标头。
-
有没有办法像浏览器一样自动关注它?
-
访问该 URL 的代码是什么?
标签: java httprequest http-status-code-303