3

I am using the QGIS (v3.16.0) ArcGisFeatureServer tool in the Browser window to try and connect to the following ArcGIS Feature Server: https://gojdippmaps.azurewebsites.net/proxy.ashx?https://maps.gov.je/arcgis/rest/services/Historic_Buildings/Historic_Buildings/FeatureServer

Note that this server requires an http referrer, such as: https://www.gov.je//citizen/Planning/Pages/HistoricEnvironmentDetail.aspx

Note also that the host is gojdippmaps.azurewebsites.net and the https://maps.gov.je.. url is treated as a parameter in the query string (preceded by ? after the path /proxy.ashx).

If I add the url as shown above I get "Connection failed: Network error" from the ArcGisFeatureServer tool. Hovering over this yields the following message:

Error transferring https://gojdippmaps.azurewebsites.net/proxy.ashx?https://maps.gov.je/arcgis/rest/services/Historic_Buildings/Historic_Buildings/FeatureServer&f=json - server replied: Bad Request

This appears to be because QGIS is trying to add f=json as a second parameter to the query string (preceded by &). If I instead make the request in a web browser (using the referrer header above) but replace the & with ? the request is successful.

Question: Is it possible (using the ArcGisFeatureServer tool or otherwise) to connect to this server and add the layer it contains to a QGIS project?

I have no expertise in Azure-hosted web applications and this is the first time I've seen a proxied url in a query string like this treated as a parameter. It appears QGIS cannot correctly deal with this scenario.

6
  • Have you tried setting the Azure URL as a proxy in QGIS settings and then just supplying the ArcGIS Feature server URL as per normal?
    – nr_aus
    Nov 25, 2020 at 3:44
  • 1
    @nr_aus, I did think of doing this, but I use a system-wide proxy in QGIS. However, I did manage to test it using https://gojdippmaps.azurewebsites.net/proxy.ashx as proxy and got another Connection failed: Network error: "Host maps.gov.je not found"
    – MatzFan
    Nov 26, 2020 at 10:00
  • 1
    its quite possible the azure web link portion is redundant. what happens wen you just try maps.gov.je/arcgis/rest/services/Historic_Buildings/… in a browser?
    – nr_aus
    Nov 27, 2020 at 1:29
  • @nr_aus, good suggestion, I did try that too. curl -H 'Referer: https://www.gov.je//citizen/Planning/Pages/HistoricEnvironmentDetail.aspx' https://maps.gov.je/arcgis/rest/services/Historic_Buildings/Historic_Buildings/FeatureServer?f=json gives 499 error "Token Required". No token is required if you use the leading azurewebsites.net part in the URL
    – MatzFan
    Nov 28, 2020 at 11:11
  • Ok interesting and tricky. Lets maybe try to eliminate some things..... Do you have ArcGIS Desktop (ArcMap or ArcGIS Pro) - are you able to connect these services using that software?
    – nr_aus
    Nov 30, 2020 at 1:21

1 Answer 1

2

I'll comment on the QGIS bug but the short answer is no, and it's going to be a fair amount of work for the QGIS guys to sort this out.

The problem is the double '?' in the query; one for the first proxy and one for the second. I'm not an RFC expert but I don't think that's very kosher, so QUrl and QUrlQuery (what QGIS is using under the hood) are getting a bit confused by the URL we need to use in the dialog.

Very weird hack to at least query the server capabilities is to add a =? to the end of your URL, which tricks QGIS and Qt into making the first MapServer queries at least somewhat correct. However as soon as you try to use one of the new exposed layers it breaks as QGIS needs to add /export, /query, etc. to the URL for interfacing with the arcgis REST stuff.

Anyways, long story short, grab this python script: https://gist.github.com/eresonance/9e3dc8f78dad2c61c38075e9c9657c53

Change the g_redirect_url to be the first part of your arcgis URL (https://gojdippmaps.azurewebsites.net/proxy.ashx) and g_referer_url to be the referer you would use in the headers (https://www.gov.je//citizen/Planning/Pages/HistoricEnvironmentDetail.aspx). Then run that bad boy with python3 in a separate console.

Now you use this as your QGIS URL: http://localhost:9999/https://maps.gov.je/arcgis/rest/services/Historic_Buildings/Historic_Buildings/FeatureServer

And because it doesn't have a ? in it anywhere, QGIS will construct the URL enpoints correctly. Those all get forwarded to the python script, which tacks the Azure proxy back on and adds the desired referer header, then grabs and returns the data from the resulting constructed proxy URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.