openlayers ProxyHost只适用于Internet Explorer

时间:2013-11-28 16:08:11

标签: jquery-mobile openlayers

我有一些问题。我使用openlayers从wms获取geoserver的数据。当我运行地图并选择功能时它的工作,但当我在谷歌铬工作。它不起作用,它给了我这个错误:无法加载资源:请求的资源上没有'Access-Control-Allow-Origin'标头。因此不允许原点'null'访问。

那是我的代码:

OpenLayers.ProxyHost =“http:// * :8080 / geoexplorer / proxy /?url =”;

1 个答案:

答案 0 :(得分:0)

现在正在运作。

 namespace KaskiGIS
    {
        public class Proxy : System.Web.IHttpHandler
        {
            public void ProcessRequest(System.Web.HttpContext context)
            {
                var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(context.Request["url"]);
                request.Method = context.Request.HttpMethod;

                if (request.Method == "POST")
                {
                    var content = new System.Text.UTF8Encoding().GetBytes(new System.IO.StreamReader(context.Request.InputStream).ReadToEnd());

                    request.ContentLength = content.Length;
                    using (var stream = request.GetRequestStream())
                    {
                        stream.Write(content, 0, content.Length);
                        stream.Close();
                    }
                }

                var response = request.GetResponse().GetResponseStream();
                if (response == null) return;

                context.Response.Write(new System.IO.StreamReader(response).ReadToEnd());
            }

            public bool IsReusable { get { return false; } }
        }
    }