Asi*_*sif 11 flask flask-restful angular
当我尝试使用anguar2 http连接到远程API时,我遇到了异常.我的Web服务器也正在接收请求并正确响应.
我能够向本地服务器发出成功的curl请求.
EXCEPTION: Response with status: 0 for URL: null
Run Code Online (Sandbox Code Playgroud)
service.ts
getAllProducts(): Observable<string> {
return this.http.get(this.productUrl)
.map(this.extractData)
}
private extractData(res: Response) {
let body = res.json();
console.log(body)
return body.data || { };
}
Run Code Online (Sandbox Code Playgroud)
希望这会对某人有所帮助。
\n\n问题出在资源定义上。当我尝试使用 angular2 连接到远程资源时http.get
,出现以下错误
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at \xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n\n使固定:
\n\n当我使用flask-restful
构建远程 API 时,下面的修复解决了我的问题
from flask_restful.utils import cors\nfrom flask_restful import Api\n\napi = Api(app, decorators=[cors.crossdomain(origin=\'*\')])\n
Run Code Online (Sandbox Code Playgroud)\n\n完整的源代码将在此处提供:库存管理器
\n 归档时间: |
|
查看次数: |
21418 次 |
最近记录: |