[OpenLayers-Users] WFS layer Cross-Origin-Resource-Sharing not working

Ryan Williams rwilliams at paqinteractive.com
Mon Jun 9 06:34:51 PDT 2014


Hi Zack,
If you want to try and keep all the code in JavaScript you can look at 
http://www.html5rocks.com/en/tutorials/cors/
I use a PHP proxy file here that uses CURL, partly because I had PHP 
programmers to help and partly because it avoids compatibility issues 
with browsers that can occur with the CORS options.
I'm a GIS guy that learned Web, and I can say the PHP proxy option 
doesn't take a lot to implement. It does require that you have PHP on 
your Web server.
Anyway, if you're interested in trying this option I attached an example 
of the code I use. It has worked well for us for years.
You'd modify it to include your domain names or IPs, and save it in the 
root folder of your website.
You would then modify the JavaScript that creates your map to set 
OpenLayers.ProxyHost to the URL of the proxy file:

OpenLayers.ProxyHost="http://192.168.0.128:443/testproxy.php?url=";

I haven't tried the CORS methods described in the link above, but I have 
used JSONP to query databases directly and that works well, but that 
requires server-side programming as well.

- Ryan


-- 
Ryan Williams
GIS Analyst / Programmer
PAQ Interactive Inc.


On 6/8/2014 3:29 PM, zachary at stauber.org wrote:
> Hello,
>
> I've been able to use OpenLayers to reference a KML file on the same 
> server as my OpenLayers script, inside an HTML file, but once have it 
> pointing to a WFS service on a GeoServer that references a PostGIS 
> table, it gives me the FireFox/FireBug error:
>
> "Cross-Origin Request Blocked: The Same Origin Policy disallows 
> reading the remote resource at 
> https://192.168.0.128:6443/geoserver/turner/wfs. This can be fixed by 
> moving the resource to the same domain or enabling CORS."
>
> Interesting thing is it is all, in fact, on the same server (all same 
> IP).  But the HTML/OpenLayers file is served up via Apache2 on port 
> 443, and the GeoServer is on Tomcat's port 6443.  But it will be on 
> different servers eventually, so regardless I need to get this 
> working.  Can anyone help?
>
> I'm a GIS guy, not a web guy (yet), not a PHP guy, so I've seen some 
> solutions suggesting a PHP proxy, but I don't understand that, and I'd 
> rather do it all in JS since I'm already using that for OpenLayers and 
> supposedly it can all work through JS.
>
> Here's the stuff in my OpenLayers HTML file called earlyvoting2.html:
>
> var earlyabsentee_wfs = new OpenLayers.Layer.Vector("Early Voting",{
>      strategies: [new OpenLayers.Strategy.Fixed()],
>      projection: map.displayProjection,
>      protocol: new OpenLayers.Protocol.WFS({
>       version: "1.1.0",
>       srsName: "EPSG:4326",
>       url: "https://192.168.0.128:6443/geoserver/turner/wfs",
>       featureNS: "https://192.168.0.128:6443/geoserver/turner",
>       featureType: "brown:earlyabsentee",
>      })
> });
>
> I'm using IP's because I haven't bought a static IP certificate yet, 
> but for purposes of this post let's say in my intranet 192.168.0.128 
> is an Ubuntu 14.04 server named Turner, and everything is on it 
> (PostGIS, Apache2, Tomcat, GeoServer, etc.).
>
> I don't quite understand, since I can bring the same layer in as a WMS 
> link in a stubbed out OpenLayers page with one layer from the Layer 
> Preview page in GeoServer, so it does CORS there.  But it hates WFS.
>
>      -Zack Stauber
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0002.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0003.html>


More information about the Users mailing list