gpt4 book ai didi

java - 在 Express.js 中访问restTemplate requestBody

转载 作者:行者123 更新时间:2023-12-02 11:03:28 27 4
gpt4 key购买 nike

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

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

另一方面,我正在使用express.js 模块来捕获此请求。以下是相关代码。

app.post('/get_leadcard', function(req, res) {
console.log(req.body);
}

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

最佳答案

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

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

关于java - 在 Express.js 中访问restTemplate requestBody,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51155077/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com