我正在尝试从smartsheet API中获取数据。当我在单独的服务器代码中使用postman和nodejs时,它可以工作。
但是,如果我在Ionic中使用带有HttpClient(@ angular / http)的API,则会在浏览器中运行时出现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);
我仍然仅收到本地主机404错误。
答案 0 :(得分:0)
如果Ionic正在使用CORS与Smartsheet API通讯,则将无法正常工作。 Smartsheet API当前不支持CORS。