【问题标题】:Need to insert variables to a Rest Call需要在 Rest Call 中插入变量
【发布时间】:2019-01-03 20:30:41
【问题描述】:

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

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

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

知道如何实现吗? 谢谢你的帮助

【问题讨论】:

  • 你试过concatenating你的变量插入字符串吗?
  • 是的,我做到了。最后我找到了怎么做。 restTemplate.postForLocation("uri.com", new HttpEntity("{\"messages\": [ { \\\"to\\\": \""+Number+"\", \"content\": \"txt \" } ] }",标题));感谢您抽出宝贵时间回复。
  • 如果您已经解决了该问题,请考虑将您的解决方案作为答案发布,以供该问题的未来读者使用。

标签: java resttemplate


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2016-01-05
    相关资源
    最近更新 更多