【发布时间】:2017-02-27 22:05:09
【问题描述】:
我有从存储原始文件中获取代码的应用程序。从公共存储库中报废很简单,如下所示:
public getRawFile(rawLink: string) {
return this.http.get(rawLink).map((res: Response) => res.text());
}
但现在我想从存储原始文件中获取代码,但来自私有存储库。如果用户有权访问(登录到存储),则加载原始文件中的源代码。
如果我尝试同样的方式,我会得到回应:
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
我该如何处理这个,cookie,获取请求的特定选项,甚至可能吗?
编辑 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());
}
但私有存储库的结果相同..
【问题讨论】:
标签: javascript angular typescript http-headers httpresponse