java - 需要在 Rest Call 中插入变量
问题描述
我有这行代码,我用它来向 api 发出一些 post 请求:
restTemplate.postForLocation("http://uri.com", new HttpEntity<>("{\"messages\": [ { \"to\": \"0213456\", \"content\": \"text\" } ] }", headers));
随着“ to ”参数的变化,我想插入一个变量而不是数字0213456,这样我就可以使用相同的代码行来处理不同的情况。
知道我怎么能做到这一点吗?谢谢您的帮助
解决方案
restTemplate.postForLocation("uri.com", new HttpEntity<>("{\"messages\": [ { \\"to\\": \""+Number+"\", \"content\": \" txt \" } ] }",标题));
推荐阅读
- html - 有没有一种简单的方法可以在页面上水平居中 Bootstrap 导航栏元素?
- google-apps-script - 如果单元格在值移动行中包含 X
- pandas - 如何将条形图中的单个条形更改为不同的颜色?
- jenkins - 有没有办法让 Jenkins 只构建 PR 而不是相应的分支,但也不删除分支作业?
- python-3.8 - Python Wheel 安装成功但无法导入模块
- python - 在python中发送和接收包
- javascript - 导入功能组件+元素类型无效时出错:需要字符串或类/函数但得到:未定义
- javascript - 车把拒绝更改 nodejs 渲染上的 h1 内部文本
- java - 我如何验证或限制枚举类型以仅接受特定值
- fortran - 如何在 Fortran 中按名称查找对象