通过 HTTP 访问 ArcGIS 数据



我正在尝试使用 GIS 数据构建地图数据 React 应用程序。我正在访问公共 GIS 端点。

终结点 http://gis.infrastructure.gov.au/infrastructure/rest/services/KeyFreightRoute/KFR/MapServer/0

在当地发展方面,它运作良好。但是,一旦推送到实时,它将返回错误:net::ERR_CONNECTION_REFUSED。因为它是一个 HTTP 端点。

ArcGIS 文档描述了一个使用 config 的解决方案,我包含了以下代码:

esriConfig.request.interceptors.push({
// set the `urls` property to the URL of the FeatureLayer so that this
// interceptor only applies to requests made to the FeatureLayer URL
urls: featureLayerUrl,
// use the BeforeInterceptorCallback to check if the query of the
// FeatureLayer has a maxAllowableOffset property set.
// if so, then set the maxAllowableOffset to 0
before: function (params) {
if (params.requestOptions.query.maxAllowableOffset) {
params.requestOptions.query.maxAllowableOffset = 0;
}
},
// use the AfterInterceptorCallback to check if `ssl` is set to 'true'
// on the response to the request, if it's set to 'false', change
// the value to 'true' before returning the response
after: function (response) {
if (!response.ssl) {
console.log('not ssl');
response.ssl = true;
}
},
});

但是,它仍然不起作用!?事实上,console.log('not ssl')甚至没有登录实时站点(但它正在本地主机上登录(。

如何访问 HTTP GIS 端点?

这更像是浏览器限制,而不是特定于 GIS 的问题。如果您当前的网址栏包含"HTTPS",则不允许该页面访问HTTP资源 - 浏览器会强制执行此操作作为安全措施。您有两种选择:

  1. 说服该网站的所有者("gis.infrastructure.gov.au"(启用HTTPS。这是当今的标准做法,而且做起来相当微不足道。他们应该这样做。
  2. 您可以在自己的服务器上运行类似于 Esri 资源代理的代理。这样,您的应用程序将通过HTTPS访问URL(因为您的服务器受到HTTPS的保护(,但是服务器在服务器站点上发出HTTP请求,从而绕过浏览器安全限制

最新更新