Tag - 跨域

跨域 TYK MicroService 微服务    2017-07-19 21:39:10    851
浏览器端报错:

"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

elasticsearch 全文检索 跨域 cors    2017-07-19 20:47:25    860
参考官方doc地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html



添加如下配置:
 http.cors.enabled: true
 http.cors.allow-origin: /http?:\/\/192.168.10.139(:[0-9]+)?/

http.cors.enabled 开启跨域访问支持,默认为false
http.cors.allow-origin 跨域访问允许的域名地址,以上使用正则,域名这里我替换了IP


重启下服务即可


 

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