node.js + Express 애플리케이션이 있습니다. 그것은 제 3 자 서비스에 제공 한 webhook을 가지고 있습니다.Node.js가 내 webhook에서 POST JSON 데이터를 읽을 수 없습니다.
{ "split_info" "널 (null)", "CUSTOMERNAME": "판매자 이름", "additionalCharges": "널 (null)"이 서비스는 다음과 같이 보입니다 JSON 본체 내은 webhook에 POST 요청을 보냅니다 "paymentMode": "CC", "해시": "a31ff1b91fd9b8ae9c82f38b02348d21fsdfd86cc828ac9a0acf82050996372cc656de3db0fe3bf9af52b73a182a77787241f3e19ec893391607301b03e70db8" "상태": "지불 릴리스", "paymentId": "551731", "인 ProductInfo": "인 ProductInfo", "customerEmail" " "value": "100.0", "udf2": "null", "notificationId": "4", "customer_highlight": " udf1 ":"null ", "udf5 ":"널 (null) ","udf4 ":"널 (null) ","udf3 ":"널 (null) ","ERROR_MESSAGE ":"아니 오류 "} 내가 POST 데이터를 읽기 위해 몸 파서 모듈을 사용하고
. 그러나 req.body 할 때 [object Object] 제공, JSON.stringify (req.body) 할 경우 {} 빈 즉 제공합니다. req.body.paymentMode와 같은 응답의 키에 액세스하려고 시도하면 정의되지 않은 상태가됩니다. mywebhook.js
var express = require('express');
var router = express.Router();
router.post('/success', function(req, res){
//this is where I need to strip the JSON request
//req.body or JSON.stringify(req.body) or anything that works
//if everything is okay then I send
res.sendStatus(200);
});
module.exports = router;
내 app.js은 다음과 같습니다 : 여기
은은 webhook 내 라우터 코드입니다var express = require('express');
var exphbs = require('express-handlebars');
var router = express.Router();
var bodyParser = require('body-parser');
var mywebhook = require('./routes/mywebhook');
var app = express();
.
.
.
app.use(bodyParser.urlencoded({'extended':'true'})); // parse application/x-www-form-urlencoded
app.use(bodyParser.json()); // parse application/json
app.use(bodyParser.json({ type: 'application/vnd.api+json' })); // parse application/vnd.api+json as json
app.use('/callwebhook', mywebhook);
.
.
.
so on
내가 뭔가를 누락되거나하고있는 중이 야 확신 잘못된 것이지만 그것을 파악할 수는 없습니다.
감사합니다.
요청의'Content-type'은'application/vnd.api + json'입니까? 이것은 나에게 이상한 것처럼 보인다. – svens
맞습니다. hookbin.com을 사용하여 thrid party webhook을 테스트했을 때 콘텐츠 유형이 다음과 같다고 말합니다 : */*. 그래서 내 app.js의 콘텐츠 유형을 app.use (bodyParser.json ({type : '*/*'})))로 변경해야합니다. – codeinprogress
좋아, 유형을 '*/*'로 변경했지만 req.body는 여전히 비어 있습니다. – codeinprogress