简体   繁体   English

mapBox Android SDK 的 WMS 授权标头

[英]WMS Authorization header for mapBox Android SDK

How to add a Authorization header when making a call to WMS services on mapBox Android SDK.如何在 mapBox Android SDK 上调用 WMS 服务时添加授权标头。

we have a satellite image service provider called Airbus.我们有一家名为空中客车公司的卫星图像服务提供商。 we want to make a call to their WMS restful API using mapBox Android SDK.我们想使用 mapBox Android SDK 调用他们的 WMS restful API。 the issue is Airbus requires us to pass a Authorization header with the key (token) when making the call for security seasons.问题是空客要求我们在发出安全季节呼叫时传递带有密钥(令牌)的授权标头。 and on mapBox SDK you can only pass the url source as a string and not the header.在 mapBox SDK 上,您只能将 url 源作为字符串传递,而不能作为标头传递。

please not we can make calls to other WMS services that doesn't require Authorization header请不要我们可以调用其他不需要授权标头的 WMS 服务

THE CODE编码

String airBus_source = "https://view.geoapi-airbusds.com/api/v1/map/imagery.wms?version=1.1.1&request=GetMap&service=WMS&WIDTH=256&HEIGHT=256&FORMAT=image/png&EPSG:3857&bbox={bbox-epsg-3857}";
            setHeader.builder.addHeader("Authorization",Airbus_key);
            setHeader.builder.url(airBus_source);
            setHeader.builder.tag(airBus_source.toLowerCase(MapboxConstants.MAPBOX_LOCALE));

            RasterSource airbus_image = new RasterSource("web-map-source",new TileSet("tileset",airBus_source),256);
            mapboxMap.addSource(airbus_image);

            RasterLayer webMapLayer = new RasterLayer("web-map-layer", "web-map-source");
            mapboxMap.addLayerBelow(webMapLayer, "aeroway-taxiway"); 

I think I found a way to do it by replacing OkHttpClient.我想我找到了一种方法来替换 OkHttpClient。 Mapbox library allows it with com.mapbox.mapboxsdk.module.http.HttpRequestUtil . Mapbox 库允许它与com.mapbox.mapboxsdk.module.http.HttpRequestUtil一起com.mapbox.mapboxsdk.module.http.HttpRequestUtil

OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .addNetworkInterceptor(chain -> {
        // check the request path if you need
        Request newRequest = chain.request()
            .newBuilder()
            .addHeader("Authorization", Airbus_key)
            .build();
        return chain.proceed(newRequest);
    })
    .build();
HttpRequestUtil.setOkHttpClient(okHttpClient);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM