我正在尝试使用Java来下载这些漫画图片。我从 HTML 代码中获取了这些图片的 URL,但是当我连接到它时,服务器告诉我我没有访问上面图片的权限。 我试图找出是否有一些帖子或获取请求来请求许可,但找不到它。有人可以帮助我了解获得访问权限的想法吗? 非常感谢^^!
和图片链接:http://webtoon.phinf.naver.net/20160901_41/1472713930299oYcIe_JPEG/147271393026973416.jpg?type=q90
拒绝消息:
推荐被拒绝 您无权访问“http://webtoon.phinf.naver.net/20160901_41/1472713930299oYcIe_JPEG/147271393026973416.jpg?”在此服务器上。 参考#24.5e41ca3.1516454916.3d5b39b
这是我下载图片的代码:
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
BufferedImage image = ImageIO.read(url);
ImageIO.write(image, "jpg", new File(output));
服务器只需检查 Referer HTTP 标头以匹配“http://www.webtoons.com/”(从页面加载图像时由浏览器自动添加)
因此通过 API 添加此标头应该足够了,以下代码为我打印 200 个成功代码:
URL url = new URL("http://webtoon.phinf.naver.net/20160901_41/1472713930299oYcIe_JPEG/147271393026973416.jpg?type=q90");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Referer", "http://www.webtoons.com/");
int responseCode = connection.getResponseCode();
System.out.println(responseCode);