【GeoServer】 geoserver 跨域問題

 

一、問題描述:

Access to fetch at 'http://localhost:8089/geoserver/wfs' from origin 'http://localhost:63342' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

 

二、解決方法:

  對  Geoserver安裝目錄下的webapps/geoserver/WEB-INF/web.xml 中的對跨域部分的註釋解除就可以了。

 參考博客中,說到把jetty-servlets-9.4.12.v20180830.jar (geoserver:本來就有了,在Geoserver安裝目錄下的lib文件夾內)放到Geoserver安裝目錄下的webapps/geoserver/WEB-INF/lib 文件夾下,但其實不用

  重啓Geoserver 服務。

參考博客:Geoserver 安裝及CORS跨域資源訪問配置

 

問題2:<iframe src = "url"> 的url跨域問題

geoserver_ol_美國地圖.html?_ijt=tuar890ntiafom37qjbmu40g48:1 Refused to display'http://localhost:8089/geoserver/topp/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=topp%3Astates&LAYERS=topp%3Astates&exceptions=application%2Fvnd.ogc.se_inimage&INFO_FORMAT=text%2Fhtml&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=-108.9228504896164%2C33.9697265625%2C-100.0458973646164%2C42.8466796875' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

問題發生的地方就是<iframe  src = url >中url的域和html的域不同導致的跨域問題。

注意: 這個問題沒辦法通過上面一個問題中的解決方法解決,因爲當前geoserver環境就是設置成可以跨域的。

博客:in a frame because it set 'X-Frame-Options' to 'sameorigin' 

新問題:

報錯:X-Frame-Options may only be set via an HTTP header sent along with a document. It may not be set inside <meta>.

解決方法:

最終結論: 當前情境下的問題無法解決,因爲我當前項目中的<iframe  src = url> 的地方只是這麼簡單。而關鍵是:這個url:

(http://localhost:8089/geoserver/topp/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=topp%3Astates&LAYERS=topp%3Astates&exceptions=application%2Fvnd.ogc.se_inimage&INFO_FORMAT=text%2Fhtml&FEATURE_COUNT=50&X=50&Y=50&SRS=EPSG%3A4326&STYLES=&WIDTH=101&HEIGHT=101&BBOX=-101.64111301302911%2C29.245605468750007%2C-97.20263645052911%2C33.68408203125001) 在瀏覽器下直接打開後結果就是一個

html,這個html是由geoserver內部通過代碼的方式生成的,所以無法修改<head>: <head http-equiv="X-Frame-Options" content="deny">,除非修改geoserver源代碼。

猜想:能否用document.get*byId()獲取到當前<iframe>然後再給其中的<head> 添加新屬性。感覺不太可能。

所以,這個問題暫時無法解決。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章