Java 需要向Rest调用插入变量
我有一行代码,用于对api进行post请求:Java 需要向Rest调用插入变量,java,resttemplate,Java,Resttemplate,我有一行代码,用于对api进行post请求: restTemplate.postForLocation("http://uri.com", new HttpEntity<>("{\"messages\": [ { \"to\": \"0213456\", \"content\": \"text\" } ] }", headers)); restTemplate.postForLocation(“http://uri.com,新的HttpEnti
restTemplate.postForLocation("http://uri.com", new HttpEntity<>("{\"messages\": [ { \"to\": \"0213456\", \"content\": \"text\" } ] }", headers));
restTemplate.postForLocation(“http://uri.com,新的HttpEntity(“{\”消息\“:[{\”到\“:\”0213456\”,\“内容\“:\”文本\“}]),标题);
随着“to”参数的更改,我想插入一个变量,而不是编号0213456,这样我就可以使用相同的代码行来处理不同的情况
你知道我怎样才能做到吗?
感谢您的帮助restemplate.postForLocation(“uri.com”,新的HttpEntity(“messages\”:[{\\\“to\\”:\\”+“\”,\“content\”:\“txt\”}),headers)) 你试过把变量插入字符串吗?是的。最后我找到了怎么做。restTemplate.postForLocation(“,新的HttpEntity(“{\\\”消息\“:[{\\\”到\\\\”:\\\“+Number+“\”,\“content\”:\“txt\”}],标题));感谢您抽出时间来响应。如果您已经解决了这个问题,请考虑将您的解决方案作为对未来读者使用此问题的答案。