[英]No 'Access-Control-Allow-Origin' header is present on the requested resource on localhost
I'm trying to make a call to the Ebay API but it wont run on my local server. 我正在尝试调用Ebay API,但它不会在我的本地服务器上运行。 I get the following error;
我收到以下错误;
No 'Access-Control-Allow-Origin' header is present on the requested resource.
所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:3000 ' is therefore not allowed access.
因此,不允许访问源' http:// localhost:3000 '。
I've read something about JSONP and headers but I don't get it. 我已经阅读了有关JSONP和标头的内容,但我不明白。 Can anyone help me explain?
谁能帮我解释一下?
Code (angular2): 代码(角度2):
@Injectable()
export class PostsService {
constructor(private http: Http) {
console.log('PostsService Initialized...')
}
getPosts() {
return this.http.get('http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=XXXXXkeyXXXX&RESPONSE-DATA-FORMAT=JSON&callback=processJSON&REST-PAYLOAD&keywords=shoe&global-id=EBAY-GB')
.map(res => <Post[]>res.json());
}
}
The api you are trying to access is made up with JSONP
so you need to access via jsonp call. 您尝试访问的api由
JSONP
组成,因此您需要通过jsonp调用进行访问。 JSONP is something like you add script
tag in your html. JSONP就像您在html中添加
script
标签一样。 And fortunately angular 2 has it's own jsonpmodule you can study it at https://angular.io/docs/ts/latest/api/http/index/JsonpModule-class.html 幸运的是,angular 2具有它自己的jsonpmodule,您可以在https://angular.io/docs/ts/latest/api/http/index/JsonpModule-class.html上进行研究
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.