# WebMapServiceImageryProvider proxy

**URL:** <https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697>\
**Category:** CesiumJS\
**Created:** [November 15, 2018, 5:45pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697 "2018-11-15T17:45:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Candan\_Eylul\_Kilseda](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/candan_eylul_kilseda/32/3276_2.png) [@Candan\_Eylul\_Kilseda](https://community.cesium.com/u/Candan_Eylul_Kilseda)\
**Post date:** [November 15, 2018, 5:45pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/1 "2018-11-15T17:45:37Z")

</div>

Hello,

I would like to set a proxy for WebMapServiceImageryProvider, however it looks like CesiumJS is ignoring the proxy I set as below:

var deformationNaples = new Cesium.WebMapServiceImageryProvider({  
url: “[http://ugbd.get-it.it/geoserver/wms](http://ugbd.get-it.it/geoserver/wms)”,  
layers: “geonode:NAPOLI\_DEFORMAZIONE\_MAP”,  
parameters: {version: “1.1.0”, transparent: “TRUE”, format: “image/png”, srs: “EPSG:4326”},  
rectangle: Cesium.Rectangle.fromDegrees(14.05072, 40.82471, 14.30817, 40.91915),  
proxy: new Cesium.DefaultProxy(“[https://ugbd.get-it.it/proxy/image/?proxyTo=](https://ugbd.get-it.it/proxy/image/?proxyTo=)”)  
});

``

[This URL](https://ugbd.get-it.it/proxy/image/?proxyTo=http://ugbd.get-it.it/geoserver/wms?version=1.1.0&transparent=TRUE&format=image%2Fpng&srs=EPSG%3A4326&bbox=14.05072%2C%2040.82471%2C%2014.30817%2C%2040.91915&service=WMS&request=GetMap&styles=&layers=geonode%3ANAPOLI_DEFORMAZIONE_MAP&width=256&height=256) works.

However I still get errors like:

Access to image at ‘[http://ugbd.get-it.it/geoserver/wms?version=1.1.0&transparent=TRUE&format=image%2Fpng&srs=EPSG%3A4326&service=WMS&request=GetMap&styles=&layers=geonode%3ANAPOLI\_DEFORMAZIONE\_MAP&bbox=13.974609374999995%2C40.78125%2C14.062500000000004%2C40.869140625&width=256&height=256](http://ugbd.get-it.it/geoserver/wms?version=1.1.0&transparent=TRUE&format=image%2Fpng&srs=EPSG%3A4326&service=WMS&request=GetMap&styles=&layers=geonode%3ANAPOLI_DEFORMAZIONE_MAP&bbox=13.974609374999995%2C40.78125%2C14.062500000000004%2C40.869140625&width=256&height=256)’ from origin ‘[http://localhost](http://localhost)’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

How can I solve this problem?

Thanks!

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [November 16, 2018, 6:18pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/2 "2018-11-16T18:18:06Z")

</div>

The fact that it’s not appending the proxy seems like a bug. I haven’t had a chance to confirm it yet, and I don’t see any issue open for it ([https://github.com/AnalyticalGraphicsInc/cesium](https://github.com/AnalyticalGraphicsInc/cesium)) so that might be worth opening a bug report for.

In the mean time though, I noticed this WMS example just sticks the proxy part at the beginning of the URL:

> **[Cesium Sandcastle](https://sandcastle.cesium.com/?src=Web%20Map%20Service%20%28WMS%29.html)**
>
> The Cesium Sandcastle provides an interactive environment for testing Cesium code.

Does that work if you do that?

The other thing to confirm this is a bug would be to open the network tab in your browser and see if you can confirm that it is indeed making a request without taking into account the specified proxy.

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [November 19, 2018, 4:01pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/3 "2018-11-19T16:01:30Z")

</div>

I did a little more digging, and it looks like the doc example is wrong, in that proxy is not an option on the WMS provider class. There’s still an issue because of a URL encoding, so I opened a bug report for it:

[https://github.com/AnalyticalGraphicsInc/cesium/issues/7272](https://github.com/AnalyticalGraphicsInc/cesium/issues/7272)

---

<div class="post-metadata">

**Author:** ![Candan\_Eylul\_Kilseda](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/candan_eylul_kilseda/32/3276_2.png) [@Candan\_Eylul\_Kilseda](https://community.cesium.com/u/Candan_Eylul_Kilseda)\
**Post date:** [November 21, 2018, 3:54pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/4 "2018-11-21T15:54:27Z")

</div>

Thanks Omar, and sorry for my late reply.

As expected in the network tab the proxy is not appended.

I tried attaching the proxy at the beginning of the URL:

var deformationNaples = new Cesium.WebMapServiceImageryProvider({  
url: “[https://ugbd.get-it.it/proxy/image/?proxyTo=http://ugbd.get-it.it/geoserver/wms](https://ugbd.get-it.it/proxy/image/?proxyTo=http://ugbd.get-it.it/geoserver/wms)”,  
layers: “geonode:NAPOLI\_DEFORMAZIONE\_MAP”,  
parameters: {version: “1.1.0”, transparent: “TRUE”, format: “image/png”, srs: “EPSG:4326”},  
rectangle: Cesium.Rectangle.fromDegrees(14.05072, 40.82471, 14.30817, 40.91915)  
});

``

This is the resulting request: [https://ugbd.get-it.it/proxy/image/?version=1.1.0&transparent=TRUE&format=image%2Fpng&srs=EPSG%3A4326&proxyTo=http%3A%2F%2Fugbd.get-it.it%2Fgeoserver%2Fwms&service=WMS&request=GetMap&styles=&layers=geonode%3ANAPOLI\_DEFORMAZIONE\_MAP&bbox=14.238281249999996%2C40.869140625%2C14.326171875000005%2C40.95703125&width=256&height=256](https://ugbd.get-it.it/proxy/image/?version=1.1.0&transparent=TRUE&format=image%2Fpng&srs=EPSG%3A4326&proxyTo=http%3A%2F%2Fugbd.get-it.it%2Fgeoserver%2Fwms&service=WMS&request=GetMap&styles=&layers=geonode%3ANAPOLI_DEFORMAZIONE_MAP&bbox=14.238281249999996%2C40.869140625%2C14.326171875000005%2C40.95703125&width=256&height=256), which is wrong. Is it because of the placement of the question mark? I have the chance to ask the proxy providers to build the proxy in a specific way.

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [November 21, 2018, 10:14pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/5 "2018-11-21T22:14:22Z")

</div>

In my own proxy, I’ve found it much more convenient to put the target URL in the path rather than the query portion of the URL. That way you can give a pre-proxied URL to just about anything (Cesium or otherwise), and it can be treated like a normal URL, even through query parameter manipulations. Here’s an example of a URL for our proxy:  
[https://nationalmap.gov.au/proxy/https://data.gov.au/geoserver/taxation-statistics-2011-12/wms?service=WMS&request=GetCapabilities](https://nationalmap.gov.au/proxy/https://data.gov.au/geoserver/taxation-statistics-2011-12/wms?service=WMS&request=GetCapabilities)

The only problem we’ve had with this is that some reverse proxies (I’m looking at you Apache) will replace the “https://” with “https:/” in the target URL (remove a slash) because the double slash is not technically allowed in a path. So our proxy just detects that and re-adds the removed slash.

---

<div class="post-metadata">

**Author:** ![Candan\_Eylul\_Kilseda](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/candan_eylul_kilseda/32/3276_2.png) [@Candan\_Eylul\_Kilseda](https://community.cesium.com/u/Candan_Eylul_Kilseda)\
**Post date:** [November 22, 2018, 9:54am UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/6 "2018-11-22T09:54:35Z")

</div>

Thanks Kevin, your suggestion works. So:

var deformationNaples = new Cesium.WebMapServiceImageryProvider({  
url: “[https://ugbd.get-it.it/proxy/image/?proxyTo=http://ugbd.get-it.it/geoserver/wms?srs=EPSG:4326&transparent=TRUE&format=image/png](https://ugbd.get-it.it/proxy/image/?proxyTo=http://ugbd.get-it.it/geoserver/wms?srs=EPSG:4326&transparent=TRUE&format=image/png)”,  
layers: “geonode:NAPOLI\_DEFORMAZIONE\_MAP”  
});

``

There is one thing I am curious about though. In this case the URL becomes [https://ugbd.get-it.it/proxy/image/?proxyTo=http%3A%2F%2Fugbd.get-it.it%2Fgeoserver%2Fwms%3Fsrs&transparent=TRUE&format=image%2Fpng&service=WMS&version=1.1.1&request=GetMap&styles=&layers=geonode%3ANAPOLI\_DEFORMAZIONE\_MAP&bbox=14.238281249999996%2C40.78125%2C14.41406249999999%2C40.95703125&width=256&height=256&srs=EPSG%3A4326](https://ugbd.get-it.it/proxy/image/?proxyTo=http%3A%2F%2Fugbd.get-it.it%2Fgeoserver%2Fwms%3Fsrs&transparent=TRUE&format=image%2Fpng&service=WMS&version=1.1.1&request=GetMap&styles=&layers=geonode%3ANAPOLI_DEFORMAZIONE_MAP&bbox=14.238281249999996%2C40.78125%2C14.41406249999999%2C40.95703125&width=256&height=256&srs=EPSG%3A4326). As you can see the first parameter’s value (EPSG:4326) is not assigned in the URL, and that happened to all the parameters that I placed first. I put there something extra temporarily (srs) so that the request is not affected. Can you guess why this is happening?

---

<div class="post-metadata">

**Author:** ![Kevin\_Ring](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/kevin_ring/32/2003_2.png) [@Kevin\_Ring](https://community.cesium.com/u/Kevin_Ring)\
**Post date:** [November 22, 2018, 11:09am UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/7 "2018-11-22T11:09:26Z")

</div>

You haven’t followed my suggestion; you’re still putting the target URL in a query parameter instead of in the path part of the URL. Given that you’re using a query parameter (proxyTo=), you can’t pre-proxy-ify the URL like that. It’s going to get mangled. WebMapServiceImageryProvider needs to be able to adjust query parameters, and it can’t do that when you’ve hidden the URL that needs to be adjusted inside a query parameter like that.

---

<div class="post-metadata">

**Author:** ![Candan\_Eylul\_Kilseda](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/candan_eylul_kilseda/32/3276_2.png) [@Candan\_Eylul\_Kilseda](https://community.cesium.com/u/Candan_Eylul_Kilseda)\
**Post date:** [November 23, 2018, 1:00pm UTC](https://community.cesium.com/t/webmapserviceimageryprovider-proxy/7697/8 "2018-11-23T13:00:15Z")

</div>

Thanks Kevin, I believe it is clear now. I asked the proxy providers to remove the query parameter (proxyTo=) from it, then I will attach the proxy in front of the target URL.
