Java 访问Express.js中的restTemplate requestBody

Java 访问Express.js中的restTemplate requestBody,java,express,spring-boot,resttemplate,Java,Express,Spring Boot,Resttemplate,我无法使用express.js模块访问正文。我正在用spring boot应用程序中的restTemplate发送请求。以下是我的请求代码 HttpEntity entity1 = new HttpEntity<>(lead, new HttpHeaders()); ResponseEntity<String> htmlResponse = restTemplate.exchange(requestUrl, HttpMethod.POST, entity1, String

我无法使用express.js模块访问正文。我正在用spring boot应用程序中的restTemplate发送请求。以下是我的请求代码

HttpEntity entity1 = new HttpEntity<>(lead, new HttpHeaders());
ResponseEntity<String> htmlResponse = restTemplate.exchange(requestUrl, HttpMethod.POST, entity1, String.class);

然而,当我运行这个程序时,它显示req.body是未定义的。正确的方法是什么?

我的程序中缺少主体解析器中间件。只需添加以下行,它现在就可以工作了

import bodyParser from 'body-parser';
app.use(bodyParser());

有帮助吗?是的。谢谢
import bodyParser from 'body-parser';
app.use(bodyParser());