GeoServer请求出现错误:拒绝访问
我现在正在用GeoServer。出现了一个问题:在我的网站中,显示地图没有问题,但是点击地图,调用GetFeatureInfo时,出现javascript错误信息:拒绝访问,
请问,这个问题怎么处理?
错误信息:
行:432
char:46
错误:拒绝访问
注:网站与GeoSerer在用一台服务器上。
代码:
map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
var params = {
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[0].params.LAYERS,
FEATURE_COUNT: 50,
Srs: 'EPSG:4326',
Styles: 'population',
Layers: 'topp:states',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: format};
OpenLayers.loadURL("http://localhost:8080/geoserver/wms", params, this, setHTML, setHTML);
OpenLayers.Event.stop(e);
});
--------------------编程问答-------------------- wfs使用了xml,xml不允许跨域访问。 --------------------编程问答-------------------- 怎么解决这个问题? --------------------编程问答-------------------- 最简单的方法:放在同一网站下
或者使用代理,ajax都有这个问题。
--------------------编程问答-------------------- 使用apache来整合!利用openlayer的proxy.cgi,具体方法我也在探索中! --------------------编程问答-------------------- 呵呵,好解决
你在使用WFS之前加上一句这样的代码
OpenLayers.ProxyHost = "/proxy/?url=";
应该就没事了吧 --------------------编程问答-------------------- 本人在IIS和geoserver同一台机里完成实例,解决了跨域问题,就以下说明,不知对有何帮助!!!!!!!
1.首先安装Python, 比如我安装到C:/Python24,安装完毕后,设置环境变量:Path,添加路径到Path之后。
2.其次,在IIS网站上添加py应用支持。在网站属性,主目录,配置,选项,应用程序映射,添加。可执行文件选择c:/python24/python.exe %s %s, 注意后面的两个%s,%s是指字符串。扩展名写上.py。这样iis就支持运行py程序了。
3.拷贝proxy.cgi程序到网站目录下,随意放哪个文件夹下,。将Proxy.cgi改名为proxy.py(很重要噢)。
4修改proxy.py中的语句,如下说明:
#!/usr/bin/env python //修改为#!C:/Python24/python.exe -u
"""This is a blind proxy that we use to get around browser
restrictions that prevent the Javascript from loading pages not on the
same server as the Javascript. This has several problems: it's less
efficient, it might break some sites, and it's a security risk because
people can use this proxy to browse the web and possibly do bad stuff
with it. It only loads pages via http and https, but it can load any
content type. It supports GET and POST requests."""
import urllib2
import cgi
import sys, os
# Designed to prevent Open Proxy type stuff.
allowedHosts = ['www.openlayers.org', 'openlayers.org',
'labs.metacarta.com', 'world.freemap.in',
'prototype.openmnnd.org', 'geo.openplans.org',
'sigma.openplans.org','localhost:8080',[color=#FF0000]//为新添加服务器[/color]
'www.openstreetmap.org']
method = os.environ["REQUEST_METHOD"]
if method == "POST":
qs = os.environ["QUERY_STRING"]
d = cgi.parse_qs(qs)
if d.has_key("url"):
url = d["url"][0]
else:
url = "http://www.openlayers.org"//修改为"http://localhost:8080/geoserver"
else:
fs = cgi.FieldStorage()
url = fs.getvalue('url', "http://www.openlayers.org")//修改为"http://localhost:8080/geoserver"
try:
host = url.split("/")[2]
if allowedHosts and not host in allowedHosts:
print "Status: 502 Bad Gateway"
print "Content-Type: text/plain"
print "This proxy does not allow you to access that location (%s)." % (host,)
print os.environ
elif url.startswith("http://") or url.startswith("https://"):
if method == "POST":
length = int(os.environ["CONTENT_LENGTH"])
headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
body = sys.stdin.read(length)
r = urllib2.Request(url, body, headers)
y = urllib2.urlopen(r)
else:
y = urllib2.urlopen(url)
# print content type header
i = y.info()
if i.has_key("Content-Type"):
print "Content-Type: %s" % (i["Content-Type"])
else:
print "Content-Type: text/plain"
print y.read()
y.close()
else:
print "Content-Type: text/plain"
print "Illegal request."
except Exception, E:
print "Status: 500 Unexpected Error"
print "Content-Type: text/plain"
print "Some unexpected error occurred. Error text was:", E
4.在html页面中OpenLayers的init()函数部分加上如下语句:
OpenLayers.ProxyHost = ‘存放位置/proxy.py?url=’。
完成,本人在windowxp中,geoserver和IIS网站同一台机上 --------------------编程问答-------------------- 我也出现了这个问题。原因是因为geoserver和tomcat不在同一台机器上,出现了跨域访问的问题。
一种临时解决办法:
在ie的“internet选项”中,在“安全”选项卡里
1. 将安全级别设为低;
2. 配置可信任站点。增加geoserver和tomcat所在的地址。注意:增加站点时,可能需要把下方“对该区域中的所有站点需要服务器验证”的勾选去掉。
补充:企业软件 , 地理信息系统