【问题标题】:OPTIONS Cors method cannot be prevented选项 Cors 方法无法阻止
【发布时间】:2015-01-15 16:31:39
【问题描述】:

在 system.config 文件中,我删除了 OPTIONS 方法声明,我正在等待必须阻止方法类型为 OPTIONS 的请求。如果我从 system.config 文件中删除其他方法类型,则会阻止具有它们的请求,但我的控件不适用于 OPTIONS 方法类型。

system.config 文件;

 CORS_ALLOW_GENERIC_HTTP_REQUESTS=true
 CORS_ALLOW_ORIGIN="*"
 CORS_SUPPORTED_METHODS=" HEAD, PUT,POST, GET, DELETE"
 CORS_SUPPORTED_HEADERS="*"   

我的 doOptions 方法;

protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  corsRequestHandler.tagRequest(request);
  CORSRequestType type = CORSRequestType.detect(request);
  if (type.equals(CORSRequestType.PREFLIGHT)) {
     try {
        corsRequestHandler.handlePreflightRequest(request, response);
     }
     catch (InvalidCORSRequestException e) {
        logger.error("Invalid CORS Request Exception: " + e.getMessage());
     }
     catch (CORSOriginDeniedException e) {
        logger.error("CORS Origin Denied Exception: " + e.getMessage());
     }
     catch (UnsupportedHTTPMethodException e) {
        logger.error("Unsupported HTTP Method Exception: " + e.getMessage());
     }
     catch (UnsupportedHTTPHeaderException e) {
        logger.error("Unsupported HTTP Header Exception: " + e.getMessage());
     }
  }
}

我没有想法,请指教。

【问题讨论】:

    标签: java servlets httprequest cors


    【解决方案1】:

    由于 OPTIONS 是一个预检请求,因此无法阻止。与简单请求不同,“预检”请求首先通过 OPTIONS 方法向对方域上的资源发送一个 HTTP 请求,以确定实际请求是否可以安全发送。

    欲了解更多信息,请访问here

    【讨论】:

      猜你喜欢
      • 2019-04-17
      • 2013-12-07
      • 2014-07-19
      • 2020-05-13
      • 2019-09-24
      • 1970-01-01
      • 2020-02-18
      • 2016-06-09
      • 1970-01-01
      相关资源
      最近更新 更多