<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi Zack,<br>
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>
<br>
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. <br>
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.<br>
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. <br>
You'd modify it to include your domain names or IPs, and save it in
the root folder of your website. <br>
You would then modify the JavaScript that creates your map to set
OpenLayers.ProxyHost to the URL of the proxy file:<br>
<br>
OpenLayers.ProxyHost="<a class="moz-txt-link-freetext" href="http://">http://</a><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">192.168.0.128:443</span></span>/testproxy.php?url=";<br>
<br>
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. <br>
<br>
- Ryan<br>
<br>
<br>
<pre class="moz-signature" cols="72">--
Ryan Williams
GIS Analyst / Programmer
PAQ Interactive Inc.</pre>
<br>
<div class="moz-cite-prefix">On 6/8/2014 3:29 PM,
<a class="moz-txt-link-abbreviated" href="mailto:zachary@stauber.org">zachary@stauber.org</a> wrote:<br>
</div>
<blockquote cite="mid:201406082041.s58KfC3K023909@ame7.swcp.com"
type="cite">
<meta name="generator" content="Windows Mail 17.5.9600.20498">
<style data-externalstyle="true"><!--
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
}
p.MsoNormal, li.MsoNormal, div.MsoNormal {
margin:0in;
margin-bottom:.0001pt;
}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst,
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle,
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast {
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
line-height:115%;
}
--></style>
<div data-externalstyle="false" dir="ltr" style="font-family:
'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI',
'Microsoft JhengHei UI', 'Malgun Gothic',
'sans-serif';font-size:12pt;">
<div>Hello,</div>
<div><br>
</div>
<div style="margin-right: 0px;" dir="ltr">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:</div>
<div style="margin-right: 0px;" dir="ltr"><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">“Cross-Origin Request Blocked: The
Same Origin Policy disallows reading the remote resource
at <a class="moz-txt-link-freetext" 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.”</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">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?</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">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.</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">Here’s the stuff in my OpenLayers
HTML file called earlyvoting2.html:</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">var earlyabsentee_wfs = new
OpenLayers.Layer.Vector("Early Voting",{<br>
strategies: [new OpenLayers.Strategy.Fixed()],<br>
projection: map.displayProjection,<br>
protocol: new OpenLayers.Protocol.WFS({<br>
version: "1.1.0",<br>
srsName: "EPSG:4326",<br>
url: "<a moz-do-not-send="true"
href="https://192.168.0.128:6443/geoserver/turner/wfs"
target="_parent">https://192.168.0.128:6443/geoserver/turner/wfs</a>",<br>
featureNS: "<a moz-do-not-send="true"
href="https://192.168.0.128:6443/geoserver/turner"
target="_parent">https://192.168.0.128:6443/geoserver/turner</a>",<br>
featureType: "brown:earlyabsentee",<br>
})</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">});</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">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.).</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage ">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.</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "> -Zack Stauber</span></span></div>
<div style="margin-right: 0px;" dir="ltr"><span class="objectBox
objectBox-errorMessage " role="presentation"><span
class="errorMessage "></span></span><br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/openlayers-users">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a></pre>
</blockquote>
<br>
</body>
</html>