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

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

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

跟之前版本对比如下:

正常Response请求:

   HTTP/1.1 200
    X-Frame-Options: SAMEORIGIN
    X-Content-Type-Options: nosniff
    geowebcache-tile-index: [13591, 9726, 14]
    Cache-Control: no-cache, no-store, must-revalidate
    Pragma: no-cache
    Expires: 0
    geowebcache-cache-result: HIT
    geowebcache-tile-index: [13591, 9726, 14]
    geowebcache-tile-bounds: 13205872.500935059,3752140.8439404294,13208318.485839844,3754586.828845214
    geowebcache-gridset: EPSG:3857
    geowebcache-crs: EPSG:3857
    Last-Modified: Wed, 08 Jan 2025 03:40:58 GMT
    Content-Disposition: inline; filename=geoserver-dispatch.image
    Content-Type: image/png
    Content-Length: 188615
    Date: Thu, 27 Feb 2025 05:48:49 GMT
    Keep-Alive: timeout=20
    Connection: keep-alive

异常Response请求:

   HTTP/1.1 200
    X-Frame-Options: SAMEORIGIN
    X-Content-Type-Options: nosniff
    geowebcache-tile-index: [13591, 9726, 14]
    Cache-Control: no-cache, no-store, must-revalidate
    Pragma: no-cache
    Expires: 0
    geowebcache-cache-result: HIT
    geowebcache-tile-index: [13591, 9726, 14]
    geowebcache-tile-bounds: 13205872.500935059,3752140.8439404294,13208318.485839844,3754586.828845214
    geowebcache-gridset: EPSG:3857
    geowebcache-crs: EPSG:3857
    Last-Modified: Wed, 08 Jan 2025 03:40:58 GMT
    Content-Disposition: inline; filename=geoserver-dispatch.image
    Content-Type: image/png
    Content-Length: 188615
    Date: Thu, 27 Feb 2025 05:48:49 GMT
    Keep-Alive: timeout=20
    Connection: 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> 

相关文章:

  • 【leetcode hot 100 42】接雨水
  • unity学习57: toggle/选项/切换, 实现单选和多选效果
  • ptaC语言4-3 求给定精度的简单交错序列部分和
  • VScode在Windows11中配置MSVC
  • 为AI聊天工具添加一个知识系统 之125 详细设计之66 逻辑和平台
  • VMware虚拟机系统扩容
  • 【Linux】线程详解
  • 事故02分析报告:慢查询+逻辑耦合导致订单无法生成
  • unity学习60: 滑动条 和 滚动条 滚动区域
  • NocoBase 本周更新汇总:新增路由管理
  • 点云处理入门--PointNetPointNet++论文与代码详解
  • python制图之小提琴图
  • Unity学习笔记之——ugui的性能优化
  • 怎么进行mysql的优化?
  • 本地搭建Koodo Reader书库结合内网穿透打造属于自己的移动图书馆
  • QT6开发高性能企业视频会议-8 使用VSCode+Copilot AI开发
  • unity TextMeshPro动态字体使用
  • 流式抽样唯一元素方案设计
  • iconfont和TTF
  • 在VSCode 中使用通义灵码最新版详细教程
  • 巴基斯坦总理:希望通过和平对话方式解决与印方问题
  • 习近平出席俄罗斯总统举行的欢迎仪式
  • 上海将发布新一版不予行政处罚清单、首份减轻行政处罚清单
  • A股26家游戏企业去年营收近1900亿元:过半净利下滑,出海成为主流选择
  • 美联储宣布维持基准利率不变
  • 短剧剧组在贵州拍戏突遇极端天气,演员背部、手臂被冰雹砸伤