원시 파일에서 코드를 가져 오는 응용 프로그램이 있습니다.개인 은닉 링크에서 텍스트 가져 오기
public getRawFile(rawLink: string) {
return this.http.get(rawLink).map((res: Response) => res.text());
}
을하지만 지금은 숨겨 놓은 원시 파일의 코드를 좀하고 싶습니다하지만 개인 저장소 : 공공의 저장소에서 폐기하는 것은 간단하다, 그것은 다음과 같습니다. 사용자가 원시 파일의 소스 코드보다 액세스 (숨김 (stash)에 로그인되어있는 경우)가로드됩니다.
XMLHttpRequest cannot load 'private_stash_file_link'. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
EXCEPTION: Response with status: 0 for URL: null
Uncaught Response with status: 0 for URL: null
어떻게 GET 요청이, 쿠키, 특정 옵션을 처리 할 수있는, 그것도 가능하다 :
은 내가 respone를 받고, 같은 방법을 시도하는 경우?편집 1.
시도 :
public getRawFile(link: string) {
let headers = new Headers();
headers.append('Access-Control-Allow-Headers', 'Content-Type');
headers.append('Access-Control-Allow-Methods', 'GET, OPTIONS');
headers.append('Access-Control-Allow-Origin', '*');
let options = new RequestOptions({headers: headers, withCredentials: true});
return this.http.get(link, options).map((res: Response) => res.text());
}
하지만 개인 저장소에 대한 동일한 결과 ..
편집 1에서와 같이 시도했지만 작동하지 않습니다. 이제는 공개 상태의 http 상태 400이 표시됩니다. – ulou
요청을받는 서버에 CORS 설정이 있습니까? – pretzo246
https://plnkr.co/edit/ogDayyIOEbOLkI8XBzOX?p=preview – ulou