OpenLayer跨域访问geoserver居然要用到代理,貌似Felx就不用。
用C#编写代理网上普遍是这样的:
public class GeoServerProxy1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["URL"] != null)
{
string url = "";
url = context.Request.QueryString["URL"].ToString();
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();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
但是上面这种情况,没有考虑post,不适用于openlayers官方的wfs协议访问,但是可以用于http查询方式的访问,例如:
JS代码:
vectorLayer = new OpenLayers.Layer.Vector("覆冰点", {
protocol: new OpenLayers.Protocol.HTTP({
//url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:V_YL_24&maxFeatures=50",
//url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:GIS_WEATHER_FORECAST&maxFeatures=50",
url: "http://10.180.80.206:9000/geoserver/sdgis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=sdgis:V_FBJC_PT&maxFeatures=50",
format: new OpenLayers.Format.GML()
}),
styleMap: new OpenLayers.StyleMap({
'default': {
strokeColor: "#00FF00",
strokeOpacity: 1,
strokeWidth: 2,
fillColor: "#FF0000",
fillOpacity: 1,
pointRadius: 6,
strokeDashstyle: 'longdashdot',
pointerEvents: "visiblePainted",
externalGraphic: "snow.gif",
graphicWidth: 12,
graphicHeight: 12,
//label: "name: ${OWNER}, age: ${FLAGS}",