我正在努力解决以下流程:
.enrichHeaders(h -> h.headerFunction("ocp-apim-subscription-key", m ->
"xxx"))
.handle(Http.outboundGateway("https://northeurope.api.cognitive.microsoft.com/vision/v3" +
".0/read/analyzeResults/abc")
.mappedRequestHeaders("ocp-apim-subscription-key")
.httpMethod(HttpMethod.GET))
.enrichHeaders(h -> h.headerFunction("ocp-apim-subscription-key", m ->
"xxx"))
.handle(Http.outboundGateway("https://northeurope.api.cognitive.microsoft.com/vision/v3" +
".0/read/analyzeResults/def")
.mappedRequestHeaders("ocp-apim-subscription-key")
.httpMethod(HttpMethod.GET))
第一个请求正确提交并且我得到了结果,对于第二个请求我得到401 UNAUTHORIZED这意味着,ocp-apim-subscription-key不包括在内。我试过没有第二个浓缩步骤,因为我认为标题不会被清除,但它也没有改变任何东西。
知道我可能做错了什么吗?我是否需要以不同的方式配置标头映射器?
这是调试的输出,它清楚地表明包含标头:
17:45:31.468 [main] DEBUG org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler - bean 'ocrDocument.http:outbound-gateway#2' for component 'ocrDocument.org.springframework.integration.config.ConsumerEndpointFactoryBean#3'; defined in: 'processing.OCRIntegrationFlow'; from source: 'bean method ocrDocument' received message: GenericMessage [payload=<200,[Transfer-Encoding:"chunked", Content-Type:"application/json; charset=utf-8", x-envoy-upstream-service-time:"25", CSP-Billing-Usage:"CognitiveServices.ComputerVision.Transaction=1", Strict-Transport-Security:"max-age=31536000; includeSubDomains; preload", x-content-type-options:"nosniff", Date:"Mon, 31 Aug 2020 15:45:31 GMT"]>, headers={Transfer-Encoding=chunked, ocp-apim-subscription-key=xxx, id=11fa4a77-d97a-772b-69b6-059de29ef808, contentType=application/json;charset=utf-8, http_statusCode=200 OK, Date=1598888731000, timestamp=1598888731467}]
更新 我已经记录了与wireshark的会话(切换到http而不是https,因为我无法让它工作)。似乎在第二个请求中没有传播订阅密钥。出于某种原因,在第二个中包含了更多标题。
第一
第二个