Я пытаюсь получить данные из API smartsheet. Когда я использую почтальон и nodejs в отдельном коде сервера, это работает.
Но если я использую API внутри Ionic с HttpClient (@ angular / http), это вызывает проблему CORS с запуском в браузере.
Failed to load https://api.smartsheet.com/2.0/sheets/1235941564208899972: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
А также я попытался с настройкой прокси, как показано ниже:
"proxies": [{
"path": "/2.0",
"proxyUrl": "https://api.smartsheet.com/"
}]
home.ts:
let headers = new Headers({ 'Access-Control-Allow-Origin': '*', 'Authorization': 'Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxx' });
let options = new RequestOptions({ headers: headers });
this.HttpClient.get('/2.0/sheets/1235941564208899972', options).pipe(
map(res => res.json())
).subscribe(data => this.response = data);
Я по-прежнему получаю только ошибку localhost 404.