groovy - Groovy 声明一个变量
问题描述
我想通过脚本在 HTTP 正文内容中设置以下详细信息。
def clientId ='ddfgertg'
def clientSecret='fghghfghfgh'
我想在下面的字符串变量中设置上面的值
def httpBody = '{ "Client_ID": "${clientId}", "Client_Secret":"${clientSecret}", "Grant_Type":"client_credentials" }'
当我打印 httpBody 时,它没有设置clinetId
,clientSecret
值。
我的实际输出
{ "Client_ID": "${clientId}", "Client_Secret":"${clientSecret}", "Grant_Type":"client_credentials" }
预期产出
{ "Client_ID": "ddfgertg", "Client_Secret":"fghghfghfgh", "Grant_Type":"client_credentials" }
解决方案
只需将 ' 转为 """,例如:
def httpBody = """{ "Client_ID": "${clientId}", "Client_Secret":"${clientSecret}", "Grant_Type":"client_credentials" }"""
会没事的。
推荐阅读
- python - 在 Linux Ubuntu 上使用 python selenium webdriver chrome 时无法找到元素
- python - “HttpResponse”对象在 DRF 中没有属性“数据”
- reactjs - 无法显示数组 React 的元素
- python - 来自许多数据框的列表。我怎样才能得到最大和最小长度的df?
- c# - 包含和连接的慢速 EF 4 查询
- stored-procedures - 存储过程挂在 statement.execute()
- google-apps-script - 使用 Google App Scripts 删除 Google Analytics 过滤器(删除不是函数错误)
- python - NetworkX 根据权重设置边缘宽度
- python - python regex re.sub:删除模式之前或之后的所有内容,直到以两种方式找到特定条件
- android - 我在 Android Studio 中构建了一个应用程序,然后将其制作为 apk,然后安装在手机中