다음 각도 2 HTTP 요청이 있습니다. 요청 때문에 플라이트의 서버 OPTIONS로 끝나는대로 각도 2 CORS 문제
이
const endpoint = '<auth_url>';
const body = {
prompt: 'consent',
grant_type: 'authorization_code',
redirect_uri: '<redirect_url>',
code: '<authorization_code>'
};
const headers = new Headers();
headers.append('Authorization', 'Basic <auth>');
headers.append('Content-Type', 'application/x-www-form-urlencoded')
const options = new RequestOptions({ headers });
this.http.post(endpoint, body, { headers: headers })
.map(res => res.json())
.subscribe(
data => console.log(JSON.stringify(data)),
error => console.error(JSON.stringify(error)),
() => console.log('Request complete')
);
node-oidc-provider
에 연결되어, I는 데 문제가 CORS으로한다. 위의 그림과 같이
Content-Type
헤더를 지정 했으므로이 경우가 아니어야합니다. Annoyingly 나는이 문제가 서버 또는 내 Angular2 코드인지 알아 내려고 노력하고 있습니까?
ExpressJS 응용 프로그램에서 CORS를 명시 적으로 활성화해야하고 그렇지 않은 경우 POST에서 올바른 헤더를 설정하면 아무런 영향을주지 않는 이유는 무엇입니까?
처럼 보이게하는 방법입니다. JS에서 할 수있는 것은 아무것도 없습니다. 따라서 Angular도 할 수 없습니다. 경우에 따라 JSONP를 사용하여 작업 할 수도 있지만 상당히 제한적입니다. –
고마워요, 아래의 답변에 대한 내 의견을 참조하십시오 – MindVox