【发布时间】:2016-08-25 10:28:37
【问题描述】:
每次我尝试通过 Java 项目加载 .png 文件时,都会出现 403 错误。奇怪的是,它适用于我以前使用的任何其他主机,直到我得到我目前使用的主机。我一直在做一些研究,它似乎是由标头引起的,因为我的主机正在检查它,所以它假设客户端是一个机器人,所以它会得到一个 403 错误。
private static Sprite BACKGROUND;
static {
try {
BACKGROUND = new Sprite(new URL("http://www.CENSORED/client/bg.png"));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
此处使用图片:
BACKGROUND.drawSprite((frameWidth / 2) - (BACKGROUND.myWidth / 2), (frameHeight / 2) - (BACKGROUND.myHeight / 2));
错误:
java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.CENSORED.com/client/bg.png
我不确定在哪里可以添加标题或任何可以帮助我绕过此错误的内容。
【问题讨论】:
-
这背后可能有多种原因...可能是您没有发送任何好的“用户代理”标头。他们的政策可能是只为列入白名单的请求来源提供服务。等
-
你能不使用Java从服务器访问图像吗?例如,如果您在 linux 中使用 wget?你和网络之间可能有代理吗?
-
403表示:
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead.可以查看http://www.CENSORED.com/client/bg.png的读取权限