如何读取流程中创建的变量并将其设置为 HTTP 请求组件中的 header?

How do I read a variable created during the flow and set it as a header in the HTTP request component?

我一直在努力访问在流程中定义的变量,现在我需要将其用作 HTTP 请求组件中授权的一部分 header。到目前为止,我尝试了以下方法:

"Bearer " ++ vars.myVar
"Bearer " ++ #[vars.myVar]
"Bearer #[vars.myVar]"

None 它们有效,因为我能够在控制台日志中看到原始输入,内容如下:

POST /webserviceurl HTTP/1.1
accept: application/json
authorization: "Bearer " ++ #[vars.myVar]
x-correlation-id: 06386edf-93a9-4d38-a117-d971f9eb7c11
Host: test.salesforce.com:443
User-Agent: AHC/1.0
Connection: keep-alive
Content-Type: application/json

这里是 HTTP 请求配置的定义:

<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="ad136a30-3119-44d1-ac13-8163214df28b" >
    <http:request-connection protocol="HTTPS" host="${SalesforceBaseUrl}" port="443" >      
    </http:request-connection>
    <http:default-headers >
        <http:default-header key="content-type" value="application/json" />
        <http:default-header key="accept" value="application/json" />
        <http:default-header key="Authorization" value='"Bearer " ++ #[vars.myVar]' />
    </http:default-headers>
</http:request-config>

我在这里缺少什么?哪一个是在那里访问变量的正确方法?

您的值不能混合,它是表达式或文字字符串(记录器中除外)。

所以在这种情况下应该是:

#["Bearer " ++ vars.myVar]