Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
托管在localhost上的爱奥尼亚请求api中的CORS问题_Api_Ionic Framework_Ionic3 - Fatal编程技术网

托管在localhost上的爱奥尼亚请求api中的CORS问题

托管在localhost上的爱奥尼亚请求api中的CORS问题,api,ionic-framework,ionic3,Api,Ionic Framework,Ionic3,我的Ionic应用程序运行在http://localhost:8100/ 我请求http://localhost:40410/api/myApi 对于api。 我知道它会遇到CORS问题,我尝试在ionic.config.json中添加代理设置,比如 当我提供服务时,我在控制台代理上添加了这个输出:/api=>https://localhost:44381/ ,但在应用程序中,我无法从api获取任何数据。 这就是我在chrome开发工具中得到的 Request URL: http://loca

我的Ionic应用程序运行在http://localhost:8100/ 我请求http://localhost:40410/api/myApi 对于api。 我知道它会遇到CORS问题,我尝试在ionic.config.json中添加代理设置,比如

当我提供服务时,我在控制台代理上添加了这个输出:/api=>https://localhost:44381/ ,但在应用程序中,我无法从api获取任何数据。 这就是我在chrome开发工具中得到的

Request URL: http://localhost:8100/api/myApi
Request Method: GET
Status Code: 500 Internal Server Error
Remote Address: 127.0.0.1:8100
这是我的ts代码

    this.http.get('/api/myApi').subscribe(
(data) => {
  console.log(data.json());
},(error) =>{
console.log(error);
}
   );

您可以使用以下参数运行chrome以禁用cors保护。
-禁用web安全性

为什么不在服务器端使用cors?@Erez.S我也有类似的问题,您能否详细说明如何在服务器端使用cors?运行npm安装cors-保存并将其添加到app.js:app.use'*',cors@Erez.S app.js?在ionic中,您的意思是app.tscors问题是服务器端问题,因此在ionic中使用客户端的cors可能是错误的!我可以理解,通过在chrome上运行禁用web安全的chrome或使用cors anywhere插件可以解决这个问题。如果我使用ionic serve-c运行相同的插件,然后在我的手机上查看它,你能告诉我它是如何运行的吗?
    this.http.get('/api/myApi').subscribe(
(data) => {
  console.log(data.json());
},(error) =>{
console.log(error);
}
   );