【问题标题】:403 Java error no permission403 Java 错误没有权限
【发布时间】: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的读取权限

标签: java http-status-code-403


【解决方案1】:

您会面临 CORS(跨域资源共享)问题吗?

当资源从与第一个资源本身所服务的域不同的域请求资源时,它会发出跨域 HTTP 请求。例如,从 domain-a.com 提供的 HTML 页面向 domain-b.com/image.jpg 发出 img src 请求。如今,网络上的许多页面都从不同的域加载资源,例如 CSS 样式表、图像和脚本。

出于安全原因,浏览器会限制从脚本中发起的跨域 HTTP 请求。例如,XMLHttpRequest 遵循同源策略。因此,使用 XMLHttpRequest 的 Web 应用程序只能向自己的域发出 HTTP 请求。为了改进 Web 应用程序,开发人员要求浏览器供应商允许 XMLHttpRequest 进行跨域请求。

更多信息

[1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
[2]: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
[3]: http://www.enable-cors.org

【讨论】:

    猜你喜欢
    • 2019-08-21
    • 1970-01-01
    • 2021-04-06
    • 2021-05-31
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多