首页 > 解决方案 > 需要在 Rest Call 中插入变量

问题描述

我有这行代码,我用它来向 api 发出一些 post 请求:

  restTemplate.postForLocation("http://uri.com", new HttpEntity<>("{\"messages\": [     {       \"to\": \"0213456\",       \"content\": \"text\"  } ] }", headers));

随着“ to ”参数的变化,我想插入一个变量而不是数字0213456,这样我就可以使用相同的代码行来处理不同的情况。

知道我怎么能做到这一点吗?谢谢您的帮助

标签: javaresttemplate

解决方案


restTemplate.postForLocation("uri.com", new HttpEntity<>("{\"messages\": [ { \\"to\\": \""+Number+"\", \"content\": \" txt \" } ] }",标题));


推荐阅读