【发布时间】: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