当我试图使用Ionic 3向API发出GET
调用时,我遇到了CORS问题。我正在使用Ionic本地服务器,在命令行中运行ionic serve
以进行实时服务器。
错误: 请求的资源上没有
'Access-Control-Allow-Origin'
头。因此不允许来源为'http://localhost:8100'
的访问。
我尝试更新ionic.config.json
中的代理设置,但似乎并没有起作用。
{
"name": "projectLeagueApp",
"app_id": "47182aef",
"type": "ionic-angular",
"integrations": {
"cordova": {}
},
"proxies": [
{
"path":"/games",
"proxyUrl": "https://api-2445582011268.apicast.io/games/"
}
]
}
我的数据服务
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class DataProvider {
headers = new Headers({'user-key': '1234567890123'});
options = new RequestOptions ({headers: this.headers});
limit: number = 50;
constructor(public http: Http) {
console.log('Hello DataProvider Provider');
}
getGames(genre, offset_num) {
let genre_id = genre;
let offset = offset_num;
return this.http.get('https://api-2445582011268.apicast.io/games/?fields=name,release_dates,screenshots&limit='+this.limit+'&offset='+offset+'&order=release_dates.date:desc&filter[genres][eq]='+genre_id+'&filter[screenshots][exists]', this.options)
}
}
我正在尝试调用这个api
请求URL
https://api-2445582011268.apicast.io
HEADERS
Key Value
user-key YOUR_KEY
Accept application/json
主要问题 我的电话通不过。我该如何为此问题创建代理?
http.get
请求中的URL更改为/games
。代理将用真实的URL替换它。 - emroussel