鍍金池/ 問答/Java/ 本地項目OPTIONS請求報500錯誤

本地項目OPTIONS請求報500錯誤

clipboard.png
前后端分離,前端是localhost:2200后端是localhost:8080和localhost:8081
發(fā)送post復(fù)雜請求會先發(fā)個options請求。但是options請求報500

改springboot配置文件也不行

endpoints.cors.allowed-methods='*'
endpoints.cors.allowed-origins='*'
endpoints.cors.allowed-headers='*'
endpoints.cors.max-age=3600
或者
management.endpoints.web.cors.allowed-methods='*'
management.endpoints.web.cors.allowed-origins='*'
management.endpoints.web.cors.allowed-headers='*'
management.endpoints.web.cors.max-age=3600

在utils里寫個filter也不行。

 0 @Component
 1 public class CorsFilter implements Filter {
 2     @Override
 3     public void init(FilterConfig filterConfig) throws ServletException {
 4         // TODO Auto-generated method stub
 5     }
 6 
 7     @Override
 8     public void doFilter(ServletRequest req, ServletResponse res,
 9         FilterChain chain) throws IOException, ServletException {
10         HttpServletResponse response = (HttpServletResponse) res;
11         response.setHeader("Access-Control-Allow-Origin", "*");
12         response.setHeader("Access-Control-Allow-Methods",
13             "POST, GET, OPTIONS, DELETE");
14         response.setHeader("Access-Control-Max-Age", "3600");
15         response.setHeader("Access-Control-Allow-Headers",
16             "Content-Type, x-requested-with, X-Custom-Header, Authorization");
17         chain.doFilter(req, res);
18     }
19 
20     @Override
21     public void destroy() {
22         // TODO Auto-generated method stub
23     }
24 }

前端用加代理http-proxy-middleware也不行。

后臺報錯
RESTEASY003655: No resource method found for options, return OK with Allow header
請問還有沒有方法?

回答
編輯回答
陌顏

很明顯后臺處理錯誤啊,沒有對應(yīng)于OPTIONS請求的處理函數(shù)。對于跨域問題,OPTIONS請求在設(shè)置了Response Header之后直接返回200就好了。

2017年5月24日 19:35
編輯回答
玄鳥

我用的網(wǎng)上的filter。
比較奇葩的是我需要@Order(1)來設(shè)定filter優(yōu)先級最高才能生效。

2017年4月27日 16:27
編輯回答
還吻

這是一個預(yù)檢請求,這個請求的錯誤碼指示的是服務(wù)器內(nèi)部錯誤。

2018年2月21日 04:24