正在 Angular 中解析远程资源

Parsing remote resource in Angular

在Angular 5,当通过http.get()访问远程资源时,关于CORS我需要考虑什么?

示例:

let url = `http://www.google.com`;
this.http.get(url).subscribe(res => {
    console.log(res.text());
    // parse html
});

结果:

Failed to load https://www.google.com/: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'null' is therefore not allowed access.
core.js:1350 ERROR 

使用 Angular 和 Firebase 生态系统,是否有解决此问题的推荐方法?我可以吗?使用云功能通过 Node.js 访问远程 url?开发人员通常如何解决这个问题?

这是跨源资源共享 (CORS)。详细了解 CORS。

与 Angular 完全无关。

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin

参考:MDN Docs for CORS