【问题标题】:CORS Restful Webservice getting blockedCORS Restful Web 服务被阻止
【发布时间】:2018-01-26 00:42:56
【问题描述】:

似乎这里有很多 CORS 的东西。一百万种方法来处理它。

将应用程序转换为 Ionic。因为WKWebView

这似乎将代码作为 ios 上的本地主机运行。这实际上意味着我需要处理 CORS。

按照这个例子。 https://amodernstory.com/2014/12/27/using-cors-headers-with-java-example/

此时它只是 web.xml 有 CorsFilter 设置。 (默认)

我以为我必须在代码中做一些事情,但我添加的任何内容似乎都没有任何区别。

会发生什么,我登录了,然后我跟踪它,这似乎工作正常。 然后代码提取用户个人资料信息。这是一个单独的 Web 服务调用。 那是被阻塞了。

polyfills.js:3 POST [webserviceURL]/user/getUser 403 (Forbidden)
(index):1 Failed to load [webserviceURL]/user/getUser: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.
    Origin 'http://localhost:8100' is therefore not allowed access.
    The response had HTTP status code 403.

第一次登录调用成功。第二个调用永远不会访问 Web 服务器。

不知道为什么。也许我需要告诉它记住起源?

【问题讨论】:

    标签: java cors


    【解决方案1】:

    尝试添加代理 URL:

    来自Handling CORS issues in Ionic

    将您的 ionic.project 文件设置为:

    {
      "name": "proxy-example",
      "app_id": "",
      "proxies": [
        {
          "path": "/api",
          "proxyUrl": "http://cors.api.com/api"
        }
      ]
    }
    

    【讨论】:

      【解决方案2】:

      您必须在 Web 服务标头中添加以下内容: 访问控制允许来源:http://localhost:8100

      另外,您可以使用 ionic native http 插件来解决 cors 问题。

      我已在我们的项目中成功使用它来解决 cors 问题。

      这里是这个插件的链接:https://ionicframework.com/docs/native/http/

      【讨论】:

        猜你喜欢
        • 2018-06-28
        • 1970-01-01
        • 2023-04-04
        • 2020-11-11
        • 2019-08-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-19
        相关资源
        最近更新 更多