2016-09-19 71 views
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() { 
    } 

} 
+0

嘗試:http://stackoverflow.com/questions/29696406/restangular-how-to-read-cookie-and-add-to-headers-at-each-查詢 –

回答

0

服務器已返回特定內容訪問控制允許來源: 你可以有給你的web應用主機URL,或動態複製原始信息(用於開發目的)。

注意:它是一個服務器端修復

+0

它似乎與您沒有使用withCredentials的其他頁面:true –

相關問題