示例页面:http ://www.amazon.com/gp/offer-listing/1589942140
public void connect( String url ) {
this.conn = Jsoup.connect( url );
}
/**
* Executes the request and parses the result.
* @return
*/
public boolean parse()
{
try {
this.page = this.conn.get();
return true;
} catch (IOException ex) {
// log it here
System.out.format("Error: %s%n", ex);
return false;
}
}
解析页面会在下面创建 ioexception:
org.jsoup.HttpStatusException:获取 URL 的 HTTP 错误。状态=204,URL= http://www.amazon.com/gp/offer-listing/1589942140
我用下面的本机 java url 类尝试了它,它没有创建 IOException:
try {
URL myURL = new URL("http://www.amazon.com/gp/offer-listing/1589942140");
URLConnection myURLConnection = myURL.openConnection();
myURLConnection.connect();
System.out.format("%s", myURLConnection.getContentType());
}
catch (MalformedURLException e) {
// new URL() failed
System.out.format("Error: %s%n", e);
}
catch (IOException e) {
// openConnection() failed
System.out.format("Error: %s%n", e);
}
任何想法为什么会这样?