微服务网关ajax转发跨域的问题解决方案

来源:互联网 发布:超级准的心理测试知乎 编辑:程序博客网 时间:2024/06/16 04:45

浏览器端报错:

“NetworkError: 403 Forbidden - http://192.168.10.147:8080/mytest/helloworld”
helloworld
已阻止跨源请求:同源策略禁止读取位于 http://192.168.10.147:8080/mytest/helloworld 的远程资源。(原因:CORS 头缺少 ‘Access-Control-Allow-Origin’)。

tomcat报错:

192.168.10.147 - - [02/Mar/2016:19:13:41 +0800] “OPTIONS /testjersey/rest/helloworld HTTP/1.1” 403 107
192.168.10.147 - - [02/Mar/2016:19:14:50 +0800] “GET /testjersey/rest/helloworld HTTP/1.1” 200 23

解析:

关于跨域,我使用的是如下地址的方案:http://blog.csdn.net/gsying1474/article/details/49664883
但是在配置方面,在web.xml中,部分配置如下

cors.supportedHeaders
Accept, Origin, X-Requested-With, Content-Type, Last-Modified

而tyk中使用了Authorization在头部信息中,
**解决办法:
在init-param配置中,“cors.supportedHeaders”配置添加Authorization即可**

0 0