2016-09-19 3 views
0

にクッキーを送信し、私は私はクッキーがGOTS HTML要求とは異なり、APIリクエストに含まれていない、それを呼び出したときに、がRestAngular要求

をRestangular.getAll機能を得ました。

私は強制場合:

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. 

ホストおよびリンクは、ページリンクとホストリンクの略語です。

EDIT:春 マイCORSFilter:動的にあなたがそこにあなたのWebアプリケーションのホストURLを与えることができる 、または:

@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

サーバーにはアクセス制御 - 許可 - 起源のための特定のコンテンツを返すことがあります(開発目的のために)原点情報をコピーする。

注:そのサーバー側の修正

+0

他のページではwithCredentialsを使用していないようです:true –