我想使用我的控制器使用Spring MVC拦截OPTIONS请求,但它被DispatcherServlet捕获.我该如何管理?
正如描述的CORS预检要求失败,因为一个标准的头,如果你发送请求到OPTIONS与端点Origin和Access-Control-Request-Method设置,那么他们得到的Spring框架截获头,和你的方法没有得到执行.接受的解决方案是使用@CrossOrigin注释来阻止Spring返回a 403.但是,我使用Swagger Codegen生成我的API代码,所以我只想禁用它并OPTIONS手动实现我的响应.
那么你可以在Spring中禁用CORS拦截吗?
我在查询我的oauth/token端点时遇到错误.
我已经为我的资源配置了cors,并且还试图允许所有资源,但没有任何工作.
XMLHttpRequest无法加载http:// localhost:8080/oauth/token.对预检请求的响应未通过访问控制检查:请求的资源上不存在"Access-Control-Allow-Origin"标头.原产地" 的http://本地主机:1111 "因此不允许访问.响应具有HTTP状态代码401.
vendor.js:1837 ERROR SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at CatchSubscriber.selector (app.js:7000)
at CatchSubscriber.error (vendor.js:36672)
at MapSubscriber.Subscriber._error (vendor.js:282)
at MapSubscriber.Subscriber.error (vendor.js:256)
at XMLHttpRequest.onError (vendor.js:25571)
at ZoneDelegate.invokeTask (polyfills.js:15307)
at Object.onInvokeTask (vendor.js:4893)
at ZoneDelegate.invokeTask (polyfills.js:15306)
at Zone.runTask (polyfills.js:15074)
defaultErrorLogger @ vendor.js:1837
ErrorHandler.handleError @ vendor.js:1897
next @ vendor.js:5531
schedulerFn @ vendor.js:4604
SafeSubscriber.__tryOrUnsub @ vendor.js:392
SafeSubscriber.next @ vendor.js:339
Subscriber._next @ vendor.js:279
Subscriber.next @ vendor.js:243
Subject.next @ vendor.js:14989
EventEmitter.emit @ vendor.js:4590
NgZone.triggerError …Run Code Online (Sandbox Code Playgroud)