我在尝试对API进行GET调用时遇到了Ionic 3的CORS问题。我正在使用离子本地服务器,在命令行中为活服务器运行离子服务器。IONIC 3 CORS ISSUE
错误 否请求的资源上存在'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
请求网址 https://api-2445582011268.apicast.io个 HEADERS 核心价值 用户键YOUR_KEY 接受应用程序/ JSON
的首要问题 我的呼叫失败。如何为这个问题创建代理?
尝试将'http.get'请求中的url更改为'/ games'。代理将用真正的替代它。 – emroussel