【问题标题】:RESTEasy POST with ajax cors error in different domainRESTEasy POST 与不同域中的 ajax cors 错误
【发布时间】:2014-04-01 10:05:00
【问题描述】:

我使用 RESTEasy 创建了 POST 服务,它在 chrome 插件中运行。 但是使用 ajax 我无法调用该服务。 得到错误

XMLHttpRequest cannot load http://localhost:8080/RESTEasyJSONExample/rest/jsonServices/send. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. 

这是因为客户端和服务器的 url 不同, 但我希望该服务器应该允许来自任何 url 的请求。所以我需要在rest api中实现CORS。我该怎么做。

【问题讨论】:

    标签: jquery ajax rest cors resteasy


    【解决方案1】:

    你可以使用RESTEasy提供的类来处理CORS。该类是CorsFilter.java,必须用作请求过滤器。您需要创建自己的类来扩展 RESTEasy 类并使用 @Provider 注释您的类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-16
      • 2022-01-21
      • 2017-12-24
      • 2013-11-26
      • 2012-12-08
      • 1970-01-01
      • 2012-01-08
      • 2018-03-16
      相关资源
      最近更新 更多