JS AJAX 调用tyk转发报跨域问题(已解决)
跨域 TYK MicroService 微服务    2017-07-19 21:39:10    852   
lightingfire   跨域 TYK MicroService 微服务
浏览器端报错:

"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中,部分配置如下
<init-param>
    <param-name>cors.supportedHeaders</param-name>
    <param-value>Accept, Origin, X-Requested-With, Content-Type, Last-Modified</param-value>
</init-param>

而tyk中使用了Authorization在头部信息中,

解决办法:
    在init-param配置中,“cors.supportedHeaders”配置添加Authorization即可
 
 

 

by 刘迎光@萤火虫工作室 
OpenBI交流群:495266201 
MicroService 微服务交流群:217722918 
mail: liuyg#liuyingguang.cn 
博主首页(==防止爬虫==):http://blog.liuyingguang.cn

Pre: mongodb3更新数据java.lang.IllegalArgumentException: Invalid BSON field name _id

Next: jersey 1.x 拦截器配置


Table of content