您好,登錄后才能下訂單哦!
環境: 服務器 geoserver2.4.1
開發機訪問服務器發布的wms 存在跨域問題,研究兩天終于找到解決方案。
主要思路是: 使用jquery的ajax 代替Groserver的request, 然后將wms的請求地址轉發到.net的處理程序, 使用.net的處理程序進行跨域處理。
function mouseClick(e) { var layer = new Array(); layer = map.getLayersByName("Simple_Geometry"); if (layer != null) for (var i = 0; i < layer.length; i++) { map.removeLayer(layer[i]); } var wms_url = "http://10.72.4.219:8089/geoserver/xj/wms?"; var params = { REQUEST: "GetFeatureInfo", BBOX: map.getExtent().toBBOX(), WIDTH: map.size.w, HEIGHT: map.size.h, X: e.xy.x, Y: e.xy.y, SERVICE: "WMS", QUERY_LAYERS: map.layers[0].params.LAYERS, INFO_FORMAT: 'text/html', FEATURE_COUNT: 50, Layers: 'xj:cswl_group', Styles: "", format: "application/vnd.ogc.gml", EXCEPTIONS: "application/vnd.ogc.se_xml", // Exception 類型 srs: 'EPSG:4326' }; var domainUrl = "crossDomain.ashx?URL="; var request = parpreUrl(wms_url, params); request = encodeURIComponent(encodeURIComponent(request)); $.post(domainUrl + request, "", function (e) { document.getElementById('nodelist').innerHTML = e; }); OpenLayers.Event.stop(e); } function parpreUrl(url, paramsObj) { for (var k in paramsObj) { url += (k + "=" + paramsObj[k] + "&"); } return url; }
如果使用Groserver.ProxyHost , 會遇到 triggerEvent未定義問題,所以使用了jqueyr的ajax代替 Geoserver.Request ,另外
public void Proce***equest(HttpContext context) { context.Response.ContentType = "text/html"; string url = ""; url = context.Request.QueryString["URL"].ToString(); url = context.Server.UrlDecode(url); HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url); loHttp.Timeout = 10000; // 10 secs loHttp.UserAgent = "Web Client"; HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse(); Encoding enc = Encoding.GetEncoding(65001); StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc); string lcHtml = loResponseStream.ReadToEnd(); context.Response.Write(lcHtml); loWebResponse.Close(); loResponseStream.Close(); }
這樣就可以解決 跨域問題
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。