0
我有一個Restangular.getAll功能,發送一個Cookie在RestAngular請求
當我把它叫做Cookie不包含在API請求,不像HTML請求誰GOTS。
如果我強迫一個:
Restangular.setDefaultHeaders({ Cookie: function() { return "foo " + $cookies.get('foo'); } })
的錯誤是:
Refused to set unsafe header "Cookie"
如果我加入的app.config:
RestangularProvider.setDefaultHttpFields({
withCredentials: true
});
的錯誤是:
XMLHttpRequest cannot load [*link*] A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.
Origin [*host*] is therefore not allowed access.
The credentials mode of an XMLHttpRequest is controlled by the withCredentials attribute.
請注意主機和鏈接是頁面鏈接和主機鏈接的縮寫。
編輯: 春天我CORSFilter:
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CORSFilter implements Filter {
public CORSFilter() {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
HttpServletRequest request = (HttpServletRequest) req;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "x-requested-with, authorization, content-type");
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_OK);
} else {
chain.doFilter(req, res);
}
}
@Override
public void init(FilterConfig filterConfig) {
}
@Override
public void destroy() {
}
}
嘗試:http://stackoverflow.com/questions/29696406/restangular-how-to-read-cookie-and-add-to-headers-at-each-查詢 –