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, zach...@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
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users

$v) { $reqfields.="&$k=$v"; }//end foreach $request = curl_init($url); // initiate curl object curl_setopt($request, CURLOPT_HEADER, 1); // set to 0 to eliminate header info from response curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($request, CURLOPT_POST,0); curl_setopt($request, CURLOPT_POSTFIELDS, $reqfields); // use HTTP POST to send form data curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response. curl_setopt($request, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($request, CURLOPT_USERPWD, 'USERNAME:PASSWORD'); //replace USERNAME and PASSWORD with a real username password that is already setup in your geoserver security properties $post_response = curl_exec($request); // execute curl post and store results in $post_response $info=curl_getinfo($request); curl_close ($request); // close curl object) header(substr($post_response,0,$info['header_size'])); echo substr($post_response,$info['header_size']); } /* * If allowed use curl to proxy to the map server, login, aquire the info, and then echo it back out */ if ($allow) { getMS(); } else { /* * Echo the error for when authentication/permission is failed */ echo $error; }//end if ?>
_______________________________________________
Users mailing list
us...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to