英文:
Bearer Token on HTTP Request
问题
我尝试用一个变量来替换令牌,这样我就不需要硬编码令牌了,但似乎我无法这样做。
这是来自Postman的输出
`"您调用了函数'+',并使用以下参数:
1: String ("Bearer ")
2: String ("eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vcHQtZGVtby1jZi1ldTEwLXNieC5hdXRoZW50...")
但它期望其中一个组合:
(Array, Any)
(Date, Period)
(DateTime, Period)
(LocalDateTime, Period)
(LocalTime, Period)
(Number, Number)
(Period, DateTime)
(Period, LocalDateTime)
(Period, Time)
(Period, Date)
(Period, LocalTime)
(Time, Period)
4| "Authorization" : 'Bearer ' + payload.message,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
跟踪:
在匿名::main (line: 4, column: 19) 中评估表达式:"output application/java
{
"Authorization" : 'Bearer ' + payload.message,
"x-qos" : "1"
}"。
`
我期望它会正常工作,因为如果我硬编码令牌,流程将正常工作。
英文:
I try to replace the token with a variable so that i dont need to hardcode the token but it seems I cant do it.
and this is the output from postman
`"You called the function '+' with these arguments:
1: String ("Bearer ")
2: String ("eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vcHQtZGVtby1jZi1ldTEwLXNieC5hdXRoZW50...)
But it expects one of these combinations:
(Array, Any)
(Date, Period)
(DateTime, Period)
(LocalDateTime, Period)
(LocalTime, Period)
(Number, Number)
(Period, DateTime)
(Period, LocalDateTime)
(Period, Time)
(Period, Date)
(Period, LocalTime)
(Time, Period)
4| "Authorization" : 'Bearer ' + payload.message,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
at anonymous::main (line: 4, column: 19)" evaluating expression: "output application/java
{
"Authorization" : 'Bearer ' + payload.message,
"x-qos" : "1"
}".
`
I expect it will wokr just fines since if i hardcode the token. The flow will work just fine.
答案1
得分: 1
以下是您要翻译的内容:
希望您对MuleSoft和DataWeave是新手。正如错误消息所指示的那样,您不能使用“+”运算符进行字符串连接。要连接两个或多个字符串,一种选择是使用++函数。另一种更高级的技巧是使用$()语法。您可以在这里了解更多关于这些方法的信息。
示例:
使用**++**进行连接
%dw 2.0
output application/json
---
{
"Authorization": "Bearer " ++ payload.message
}
使用**$()**进行连接
%dw 2.0
output application/json
---
{
"Authorization": "Bearer $(payload.message)"
}
英文:
Hope you are new to MuleSoft and DataWeave. As the error message indicates, you cannot use the "+" operator for string concatenation. To concatenate two or more strings, one option is to use the ++ function. Another more advanced technique is to use the $() syntax. You can read more about these methods here
Example:
Using ++ for concatenation
%dw 2.0
output application/json
---
{
"Authorization": "Bearer " ++ payload.message
}
Using $() for concatenation
%dw 2.0
output application/json
---
{
"Authorization": "Bearer $(payload.message)"
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论