当前位置: 首页 > news >正文

请求Geoserver的WTMS服务返回200不返回图片问题-跨域导致

今天碰到个奇怪问题,改了个页面标题再打包布署GeoServer发现调用WTMS服务失败,请求返回状态码200,返回包大小0,使用postman模拟请求是可以正常返回图片的。

跟之前版本对比如下:

正常Response请求:

   HTTP/1.1 200X-Frame-Options: SAMEORIGINX-Content-Type-Options: nosniffgeowebcache-tile-index: [13591, 9726, 14]Cache-Control: no-cache, no-store, must-revalidatePragma: no-cacheExpires: 0geowebcache-cache-result: HITgeowebcache-tile-index: [13591, 9726, 14]geowebcache-tile-bounds: 13205872.500935059,3752140.8439404294,13208318.485839844,3754586.828845214geowebcache-gridset: EPSG:3857geowebcache-crs: EPSG:3857Last-Modified: Wed, 08 Jan 2025 03:40:58 GMTContent-Disposition: inline; filename=geoserver-dispatch.imageContent-Type: image/pngContent-Length: 188615Date: Thu, 27 Feb 2025 05:48:49 GMTKeep-Alive: timeout=20Connection: keep-alive

异常Response请求:

   HTTP/1.1 200X-Frame-Options: SAMEORIGINX-Content-Type-Options: nosniffgeowebcache-tile-index: [13591, 9726, 14]Cache-Control: no-cache, no-store, must-revalidatePragma: no-cacheExpires: 0geowebcache-cache-result: HITgeowebcache-tile-index: [13591, 9726, 14]geowebcache-tile-bounds: 13205872.500935059,3752140.8439404294,13208318.485839844,3754586.828845214geowebcache-gridset: EPSG:3857geowebcache-crs: EPSG:3857Last-Modified: Wed, 08 Jan 2025 03:40:58 GMTContent-Disposition: inline; filename=geoserver-dispatch.imageContent-Type: image/pngContent-Length: 188615Date: Thu, 27 Feb 2025 05:48:49 GMTKeep-Alive: timeout=20Connection: keep-alive

发现异常中没有:Access-Control-Allow-Origin
才想起来之前好像配置过跨域:

修改跨域:web.xml

注意如果按deepseek推荐使用org.eclipse.jetty.servlets.CrossOriginFilter这个类需要添加jar包(jetty-servlets-9.4.56.v20240826.jar, jetty-util-9.4.56.v20240826.jar)

下面我推荐tomcat的,不用加jar包

<!-- Uncomment following filter to enable CORS in Tomcat. Do not forget the second config block further down. --><filter><filter-name>cross-origin</filter-name><filter-class>org.apache.catalina.filters.CorsFilter</filter-class><init-param><param-name>cors.allowed.origins</param-name><param-value>*</param-value></init-param><init-param><param-name>cors.allowed.methods</param-name><param-value>GET,POST,PUT,DELETE,HEAD,OPTIONS</param-value></init-param><init-param><param-name>cors.allowed.headers</param-name><param-value>*</param-value></init-param></filter><!-- Uncomment following filter-mapping to enable CORS --><filter-mapping><filter-name>cross-origin</filter-name><url-pattern>/*</url-pattern></filter-mapping>

完了记录清理Tomcat缓存:apache-tomcat-8.5.99\work\Catalina\localhost
重启Tomcat就可以正常使用。

如果需要修改缓存目录,修改geoserver中web.xml,增加

   <context-param><param-name>GEOSERVER_DATA_DIR</param-name><param-value>E:\map\geoserver-2.15.0\webapps\geoserver\data</param-value></context-param><context-param><param-name>GEOWEBCACHE_CACHE_DIR</param-name><param-value>E:\map\geoserver-2.15.0\cache</param-value></context-param> 
http://www.lryc.cn/news/543899.html

相关文章:

  • ubuntu配置jmeter
  • 《Qt动画编程实战:轻松实现头像旋转效果》
  • 【Mac电脑本地部署Deepseek-r1:详细教程与Openwebui配置指南】
  • DeepSeek开源技术全景解析:从硬件榨取到AI民主化革命
  • WPF12-MVVM
  • 一个原教旨的多路径 TCP
  • 跟着AI学vue第十三章
  • labview中VISA串口出现异常的解决方案
  • StableDiffusion本地部署 2
  • unity学习61:UI布局layout
  • BRD4缺失通过GRP78灭活内质网应激,延缓脱氢表雄酮诱导的卵巢颗粒细胞凋亡
  • Jmeter插件下载及安装
  • 【Swift 算法实战】判断数组中是否存在重复元素
  • Spock框架:让单元测试更优雅的高效武器
  • 【前端基础】Day 4 CSS盒子模型
  • 补题蓝桥杯14届JavaB组第4题
  • kotlin的函数标准库使用
  • Visual Studio Code 跨平台安装与配置指南(附官方下载链接)
  • STM32学习【4】ARM汇编(够用)
  • Linux驱动开发实战(一):LED控制驱动详解
  • windows下安装pyenv+virtualenv+virtualenvwrapper
  • Cherno 游戏引擎笔记(91~111)
  • 0x02 js、Vue、Ajax
  • Windows 11【1001问】删除Win11左下角小组件的6种方法
  • 【动手学深度学习】基于Python动手实现线性神经网络
  • leetcode 912. 排序数组
  • 【芯片设计】NPU芯片前端设计工程师面试记录·20250227
  • BUU40 [CSCCTF 2019 Qual]FlaskLight1【SSTI】
  • WiFi IEEE 802.11协议精读:IEEE 802.11-2007,6,MAC service definition MAC服务定义
  • 2025学年安徽省职业院校技能大赛 “信息安全管理与评估”赛项 比赛样题任务书