我在使用请求方法 POST 进行 API 调用时遇到问题。预检 OPTIONS 方法失败。我在 weblogic 12c 上运行 ATG。以下是我的 CORS 代码
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import atg.servlet.*;
import atg.servlet.pipeline.*;
public class CORSHeaderServlet extends InsertableServletImpl{
public CORSHeaderServlet () {}
public void service (DynamoHttpServletRequest request,
DynamoHttpServletResponse response)
throws IOException, ServletException
{
//add headers to response.
response.addHeader("Access-Control-Allow-Origin" ,"*");
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE, OPTIONS");
response.addHeader("Access-Control-Allow-Headers","Origin, Content-Type, X-Auth-Token, X-PINGOTHER");
response.addHeader("Access-Control-Max-Age", "86000");
passRequest (request, response);
}
}
浏览器错误是
Access to XMLHttpRequest at 'http://localhost:7003/rest/model/atg/userprofiling/ProfileActor/login' from origin 'http://localhost' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status
Java错误是
]] Root cause of ServletException.
javax.servlet.ServletException: The request method type is not supported: OPTIONS
at atg.rest.servlet.RestPipelineServlet.serviceRESTRequest(RestPipelineServlet.java:493)
at atg.rest.servlet.RestPipelineServlet.service(RestPipelineServlet.java:274)
at atg.servlet.pipeline.PipelineableServletImpl.passRequest(PipelineableServletImpl.java:157)
at atg.servlet.pipeline.PipelineableServletImpl.service(PipelineableServletImpl.java:320)
at atg.rest.servlet.RestPipelineServlet.service(RestPipelineServlet.java:278)
Truncated. see log file for complete stacktrace
对此的任何帮助将不胜感激。