【问题标题】:how to overcome CORS error in IONIC Vue 3 android build?如何克服 IONIC Vue 3 android 构建中的 CORS 错误?
【发布时间】:2021-02-26 00:02:45
【问题描述】:

我正在使用一个允许本地主机 CORS 的 rest api。当我使用 ionic 应用程序的网络版本时,我按预期从服务器获得响应。但是当它来到android模拟器时 它给了我以下错误,我的 Api 只允许来自本地主机或我的域。如何解决这个问题?

**Msg: Failed to load https://myapi.com/GetAllUsersList: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost, *', but only one is allowed. Origin 'http://localhost' is therefore not allowed access.**

【问题讨论】:

    标签: android ionic-framework cors vuejs3


    【解决方案1】:

    请使用 HTTP 插件为您的应用检查以下链接

    https://ionicframework.com/docs/native/http
    

    【讨论】:

      【解决方案2】:

      回答我自己的问题!! 我们可以改变 url 电容器的用途,这将改变原点。我们可以使用以下属性编辑 capasitor.config.json

      "server": {
          "hostname": "mydomain.com", //in my case this is localhost
          "androidScheme": "https"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多