Spring integration 如何在Spring集成Rest服务调用的Http.outboundGateway中添加cutom头?

Spring integration 如何在Spring集成Rest服务调用的Http.outboundGateway中添加cutom头?,spring-integration,custom-headers,header-enricher,Spring Integration,Custom Headers,Header Enricher,我正在尝试使用自定义头进行RESTWeb服务POST方法调用。试图在enrichHeaders中添加自定义标头,但仍收到HTTP 403禁止响应。您能帮我翻译一下正确的代码片段吗 .enrichHeaders(h -> h.header("X-API-Key","ABCEDABCED").header(CONTENT_TYPE, APPLICATION_JSON_VALUE).header(APP_NAME, XXX).header(ACCEPT,

我正在尝试使用自定义头进行RESTWeb服务POST方法调用。试图在enrichHeaders中添加自定义标头,但仍收到HTTP 403禁止响应。您能帮我翻译一下正确的代码片段吗

.enrichHeaders(h -> h.header("X-API-Key","ABCEDABCED").header(CONTENT_TYPE, APPLICATION_JSON_VALUE).header(APP_NAME, XXX).header(ACCEPT,
                        APPLICATION_JSON_VALUE))
                .handle(Http.outboundGateway(config.getXxxWebServiceUrl()).httpMethod(HttpMethod.POST)
                        .expectedResponseType(String.class).requestFactory(xxxRequestFactory()),
                        c -> c.advice(sendToArchive.sendToArhive()))
                .log().get();

错误日志:-

[bean 'xxxDispatcher1.http:outbound-gateway#0' for component 'xxxDispatcher1.org.springframework.integration.config.ConsumerEndpointFactoryBean#2'; defined in: 'class path resource [service/xxxDispatcher.class]'; from source: 'bean method xxxDispatcher1']; nested exception is org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: [{"message":"Forbidden"}]
    at 

请参阅文档中的标题映射部分:

默认情况下,所有标准HTTP头都从消息映射到HTTP请求或响应头,无需进一步配置


因此,由于您没有为
Http.outboundGateway()
提供
mappedRequestHeaders()
选项,因此您的
APP_NAME
自定义头不会被映射,也不会通过Http传输到REST服务。

请参阅文档中的头映射部分:

默认情况下,所有标准HTTP头都从消息映射到HTTP请求或响应头,无需进一步配置


因此,由于您没有为
Http.outboundGateway()
提供
mappedRequestHeaders()
选项,因此您的
APP\u NAME
自定义头不会被映射,也不会通过Http传输到REST服务。

Awesome mate,这很有效。谢谢你的及时解决方案。太棒了,伙计,真管用。谢谢你的及时解决。