2016-06-02 2 views
0

저는 휴식 웹 서비스를 보유하고 있으며 이제는 ionic 2 프론트 엔드 앱에서 인증 나머지 방법으로 게시물 요청을 보내려합니다. 내 로그인 구성 요소에요청한 리소스에 'Access-Control-Allow-Origin'헤더가 없습니다. Ionic 2

내가 가진 내 공급자에

...this._restClient.post(
       'authentication', 
       body, 
       (data) => this.handleSuccessAuthenticate(data), 
       (data) => this.handleErrorAuthenticate(data) 
      );... 

을 내 _restClient 코드는 다음과 같습니다

public post(resource: string, data: Object, onSuccess: restClient, onError: callbackRestClient) { 
     var httpResult: Observable<Response>; 


     if (data === null) { 
      httpResult = this._http.post(this.getUrl(resource), '{}', { headers: this.getHeaders() }); 
     } else { 
      httpResult = this._http.post(this.getUrl(resource), JSON.stringify(data), { headers: this.getHeaders() }); 
     } 


     this.handleResult(httpResult, onSuccess, onError); 
    } 

또한 헤더를 설정하는 개인 방법이 있습니다

private getHeaders() { 
     var headers = new Headers(); 
     headers.append('Accept', 'application/json'); 
     headers.append('Content-Type', 'application/json'); 
     headers.append('Access-Control-Allow-Origin', '*'); 
     headers.append('Access-Control-Allow-Credentials', 'true'); 
     headers.append("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE"); 
     headers.append("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token"); 

     return headers; 
    } 

을 기본 메시지 :

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource 

내가 뭘 잘못하고있는거야?

+2

이 좋은 티에리의 답변을 참조하십시오 http://stackoverflow.com/questions/36768418/how-to-make -cors-enabled-http-requests-in-angular-2/36768488 # 36768488 – yurzui

답변

1

실제로 서버 측 문제이며 Angular2가 아닙니다. 프리 플라이트 된 OPTIONS 요청은 응답에 Access-Control-Allow-Origin 헤더를 리턴해야합니다.

은 자세한 내용은이 문서를 참조하십시오

+0

내가 할 수있는 일이있어서 서버를 소유하고 있지 않기 때문에 클라이언트 쪽에서 우회 할 수 있습니다. –

관련 문제