[英]Decode JSON object in req where content type 'application/x-www-form-urlencoded'
I have integration with payment service, and he send me a curl like this curl -d '{"merchantAccount":"pipedrive_youscore_rubicon_ltd","orderReference":"WFP-BTN-7181819-635e48482b33d","merchantSignature":"7bff82ec724b2a3ade7fe74e3b829f2c","amount":3,"currency":"UAH","authCode":"326470","email":"rubicon.sergii@gmail.com","phone":"380669114250","createdDate":1667123272,"processingDate":1667123284,"cardPan":"44****6705","cardType":"Visa","issuerBankCountry":"Ukraine","issuerBankName":"MONObank","recToken":"","transactionStatus":"Approved","reason":"Ok","reasonCode":1100,"fee":0.07,"paymentSystem":"googlePay","acquirerBankName":"WayForPay","cardProduct":"credit","clientName":"Rubicon Sergii","products":[{"name":"Тестовий товар","price":3,"count":1}],"clientFields":[{"name":"Домен порталу","value":"rawgsag"}]}' http://app.rubicon.tips:3000/checkSupPay
我与支付服务集成,他给我发了一个 curl 像这样curl -d '{"merchantAccount":"pipedrive_youscore_rubicon_ltd","orderReference":"WFP-BTN-7181819-635e48482b33d","merchantSignature":"7bff82ec724b2a3ade7fe74e3b829f2c","amount":3,"currency":"UAH","authCode":"326470","email":"rubicon.sergii@gmail.com","phone":"380669114250","createdDate":1667123272,"processingDate":1667123284,"cardPan":"44****6705","cardType":"Visa","issuerBankCountry":"Ukraine","issuerBankName":"MONObank","recToken":"","transactionStatus":"Approved","reason":"Ok","reasonCode":1100,"fee":0.07,"paymentSystem":"googlePay","acquirerBankName":"WayForPay","cardProduct":"credit","clientName":"Rubicon Sergii","products":[{"name":"Тестовий товар","price":3,"count":1}],"clientFields":[{"name":"Домен порталу","value":"rawgsag"}]}' http://app.rubicon.tips:3000/checkSupPay
Where content type 'application/x-www-form-urlencoded'
其中内容类型为'application/x-www-form-urlencoded'
And on server i have next req.body在服务器上我有下一个 req.body
body: [Object: null prototype] {
"'{merchantAccount:pipedrive_youscore_rubicon_ltd,orderReference:WFP-BTN-7181819-635e48482b33d,merchantSignature:7bff82ec724b2a3ade7fe74e3b829f2c,amount:3,currency:UAH,authCode:326470,email:rubicon.sergii@gmail.com,phone:380669114250,createdDate:1667123272,processingDate:1667123284,cardPan:44****6705,cardType:Visa,issuerBankCountry:Ukraine,issuerBankName:MONObank,recToken:,transactionStatus:Approved,reason:Ok,reasonCode:1100,fee:0.07,paymentSystem:googlePay,acquirerBankName:WayForPay,cardProduct:credit,clientName:Rubicon Sergii,products:[{name:\\u0422\\u0435\\u0441\\u0442\\u043e\\u0432\\u0438\\u0439 \\u0442\\u043e\\u0432\\u0430\\u0440,price:3,count:1}],clientFields:[{name:\\u0414\\u043e\\u043c\\u0435\\u043d \\u043f\\u043e\\u0440\\u0442\\u0430\\u043b\\u0443,value:rawgsag}]}'": ''
},
I think this req.body
parsed like 'application/x-www-form-urlencoded'
but in body json object, how to parse it?我认为这个req.body
解析为'application/x-www-form-urlencoded'
但在 body json object 中,如何解析它?
I trying parse with express.urlencoded({ extended: false })
express.urlencoded({ extended: false, type: 'application/json' })
and express.json({ strict: false, type: 'application/x-www-form-urlencoded' })
with all options, but i cant parse it correctly我尝试用express.urlencoded({ extended: false })
express.urlencoded({ extended: false, type: 'application/json' })
和express.json({ strict: false, type: 'application/x-www-form-urlencoded' })
具有所有选项,但我无法正确解析它
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true })); // support encoded bodies
// With body-parser configured, now create our route. We can grab POST
// parameters using req.body.variable_name
// POST http://localhost:8080/api/books
// parameters sent with
app.post('/api/books', function(req, res) {
var book_id = req.body.id;
var bookName = req.body.token;
//Send the response back
res.send(book_id + ' ' + bookName);
});
From https://stackoverflow.com/a/42129247/17278956来自https://stackoverflow.com/a/42129247/17278956
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.