[英]HttpURLConnection: resulting json-code suggests page doesnt exist (404), even when url is correct
[英]HttpURLConnection respond 404 when file clearly exist
我有一个Java程序正在尝试从URL读取任何文件。 但是,当文件明确存在时,它将返回404错误,请尝试使用URL自己尝试。 怎么了?
URL url = new URL("http://images.all-free-download.com/images/graphiclarge/blue_abstract_background_310971.jpg");
HttpURLConnection myHTTPConTest = null;
myHTTPConTest = (HttpURLConnection) url.openConnection();
int responseCode = myHTTPConTest.getResponseCode(); // Returns 404
添加了用户代理,没有更改:
myHTTPConTest.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401");
我认为您运气不好,只是碰到服务器重启时间之类的。 因为现在返回200。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.