首页 > 解决方案 > 将标头值添加到磁贴请求

问题描述

有没有办法在 ArcGIS 4.9 中向切片请求添加标头值。我正在使用WebTileLayer并且我正在连接的磁贴服务器使用 Azure Active Directory 身份验证,这需要在每个磁贴请求的标头中传递详细信息。

我试过使用拦截器

esriConfig.request.interceptors = [{
    urls: [/atlas.microsoft.com/],
    before: async function (params) {
        params.requestOptions.headers = {
            'x-ms-client-id': clientId,
            Authorization: 'Bearer ' + token
        };
    }
}];

我也试过:

esriConfig.request.interceptors.push({
    urls: [/atlas.microsoft.com/],
    authMode: 'anonymous',
    headers: {
        'x-ms-client-id': clientId,
        Authorization: 'Bearer ' + token
    }
});

但标头值永远不会添加到磁贴请求中。

标签: arcgis-js-api

解决方案


Finally figured it out. In versions 4.9 and below of ArcGIS JavaScript API, headers are ignored on image requests. This was fixed in version 4.10.

In my case the following added the headers I needed to tile requests once I pointed to version 4.10:

esriConfig.request.interceptors.push({
    urls: [/atlas.microsoft.com/],
    headers: {
        'x-ms-client-id': clientId,
        Authorization: 'Bearer ' + token
    }
});

推荐阅读