为什么这段代码会抛出java.io.FileNotFoundException,即使url工作正常

为什么这段代码会抛出java.io.FileNotFoundException,即使url工作正常,java,http,Java,Http,我在这个特定的网站(nandos.co.uk/southharrow)上发现了这个错误。其他URL工作正常。有人知道为什么吗 java.io.FileNotFoundException:位于 sun.net.www.protocol.http.HttpURLConnection.getInputStream(未知 (来源) 该地址不存在URL。您看到的页面是出现错误时显示的默认页面。类似于“FileNotFoundException” 该地址不存在URL。您看到的页面是出现错误时显示的默认页面。

我在这个特定的网站(nandos.co.uk/southharrow)上发现了这个错误。其他URL工作正常。有人知道为什么吗

java.io.FileNotFoundException:位于 sun.net.www.protocol.http.HttpURLConnection.getInputStream(未知 (来源)

该地址不存在URL。您看到的页面是出现错误时显示的默认页面。类似于“FileNotFoundException”


该地址不存在URL。您看到的页面是出现错误时显示的默认页面。与“FileNotFoundException”类似,URL似乎不正确并返回404,这被解释为FileNotFoundException:

> GET /southharrow HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: www.nandos.co.uk
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Wed, 29 Jan 2014 21:28:59 GMT
< Server: Apache
< X-Powered-By: PHP/5.3.27
>GET/southharrow HTTP/1.1
>用户代理:curl/7.24.0(x86_64-apple-darwin12.0)libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
>主持人:www.nandos.co.uk
>接受:*/*
>
未找到

您应该再次验证URL路径。此外,您可能希望尝试使用
curl
进行快速测试。

URL似乎不正确,并返回404,这被解释为FileNotFoundException:

> GET /southharrow HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: www.nandos.co.uk
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Wed, 29 Jan 2014 21:28:59 GMT
< Server: Apache
< X-Powered-By: PHP/5.3.27
>GET/southharrow HTTP/1.1
>用户代理:curl/7.24.0(x86_64-apple-darwin12.0)libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
>主持人:www.nandos.co.uk
>接受:*/*
>
未找到

您应该再次验证URL路径。此外,您可能想尝试使用
curl
进行快速测试。

谢谢,这很有意义,有没有办法检测到存在默认页面并下载该页面?我相信您可以使用
http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#getErrorStream()
获取返回的数据,即使没有返回2xx代码。检查响应代码(
getResponseCode
),并根据状态使用正确的流方法。谢谢,这很有意义,有没有办法检测到存在默认页面并下载该页面?我相信您可以使用
http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html#getErrorStream()
获取返回的数据,即使没有返回2xx代码。检查响应代码(
getResponseCode
),并根据状态使用正确的流方法。
> GET /southharrow HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: www.nandos.co.uk
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Date: Wed, 29 Jan 2014 21:28:59 GMT
< Server: Apache
< X-Powered-By: PHP/5.3.27