<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body style='font-family: Verdana,Geneva,sans-serif'>
<p>On Jun 9 2014 7:41 AM, openlayers-users-request@lists.osgeo.org wrote:</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%"><!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<pre>OK, thanks for the recommendation on the PHP solution.  I may have to bite the bullet and start learning about PHP.  I've seen that HTML5Rocks page before, but it talks about GET and POST requests and XmlHttpRequest, and I'm sure OpenLayers is doing that under the hood, but it's all wrapped in the OpenLayers JavaScript as far as the user is concerned, so I am not sure how to apply it in this case.<br /><br />I was hoping there was some way of enabling a flag on the JS parameter object that creates the layer that just does makes CORS work.  Somehow Esri's JavaScript widgets are able to bring in data from any number of various sources, and this issue never comes up, so they are be doing their own enabling built into their widget methods I guess.  This seems like a really big limitation considering one of the main uses of OpenLayers is to mash up layers from various sources.<br /><br />     -Zack Stauber<br /><br />Date: Mon, 09 Jun 2014 08:34:51 -0500
From: Ryan Williams <<a href="mailto:rwilliams@paqinteractive.com">rwilliams@paqinteractive.com</a>>
To: <a href="mailto:openlayers-users@lists.osgeo.org">openlayers-users@lists.osgeo.org</a>
Subject: Re: [OpenLayers-Users] WFS layer
        Cross-Origin-Resource-Sharing not working
Message-ID: <<a href="mailto:5395B7FB.5060608@paqinteractive.com">5395B7FB.5060608@paqinteractive.com</a>>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Hi Zack,
If you want to try and keep all the code in JavaScript you can look at 
<a href="http://www.html5rocks.com/en/tutorials/cors/">http://www.html5rocks.com/en/tutorials/cors/</a>
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="<a href="http://192.168.0.128:443/testproxy.php?url=">http://192.168.0.128:443/testproxy.php?url=</a>";

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, <a href="mailto:zachary@stauber.org">zachary@stauber.org</a>wrote:</pre>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">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 <a href="https://192.168.0.128:6443/geoserver/turner/wfs">https://192.168.0.128:6443/geoserver/turner/wfs</a>. 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: "<a href="https://192.168.0.128:6443/geoserver/turner/wfs">https://192.168.0.128:6443/geoserver/turner/wfs</a>", featureNS: "<a href="https://192.168.0.128:6443/geoserver/turner">https://192.168.0.128:6443/geoserver/turner</a>", 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 <a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a> <a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a></blockquote>
<pre>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <<a href="http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment.html">http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment.html</a>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <<a href="http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0001.html">http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140609/9881cf95/attachment-0001.html</a>>

------------------------------

_______________________________________________
Users mailing list
<a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a>
<a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a>

End of Users Digest, Vol 93, Issue 5
************************************
</pre>
</blockquote>
<p> </p>
<p> </p>
<div> </div>
</body></html>