EXCEPTION:响应状态:0表示URL:null表示angular2 [英] EXCEPTION: Response with status: 0 for URL: null in angular2
问题描述
我可以向本地服务器发出成功的curl请求。
EXCEPTION:状态为0的响应:null
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 || {};
}
问题在于资源定义。当我尝试使用angular2 http.get
连接到远程资源时,出现以下错误:
<$ p $
FIX: 当我使用 I'm getting following exception, when I'm trying to connect to remote API using anguar2 http. Also my web server is receiving request and responding properly. I'm able to make a successful curl request to the local server. service.ts
Hope this will helps someone. The problem was with resource definition. When I'm trying to connect to remote resource using angular2 FIX: As I'm using Complete source code will be available here : inventory-manager 这篇关于EXCEPTION:响应状态:0表示URL:null表示angular2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b $ 跨源请求被阻止:同源策略不允许读取远程资源。 b
flask-restful
构建远程API时,下面的解决方案解决了我的问题
from flask_restful.utils import cors $ b $ from flask_restful import Api
api = Api(app,decorators = [cors.crossdomain(origin ='*')])
EXCEPTION: Response with status: 0 for URL: null
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 || { };
}
http.get
, I was getting following errorCross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at …
flask-restful
to build remote API, below fix solved my problemfrom flask_restful.utils import cors
from flask_restful import Api
api = Api(app, decorators=[cors.crossdomain(origin='*')])