简体   繁体   English

在请求中解码 JSON object,其中内容类型为“application/x-www-form-urlencoded”

[英]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.

相关问题 如何将Content-Type:appication / x-www-form-urlencoded更改为application / json? - How to change Content-Type: appication/x-www-form-urlencoded to application/json? 如何使用“内容类型”:“ application / x-www-form-urlencoded”发出发布请求? - How to make a Post request with “content type”: “application/x-www-form-urlencoded”? 从 postman 发送 application/x-www-form-urlencoded 时读取 req.body 内容的问题 — bodyparser 已使用 - Issue reading req.body content when sending application/x-www-form-urlencoded from postman — bodyparser already used 如何在 node.js 中发布内容类型 ='application/x-www-form-urlencoded' 的数据 - how to post data in node.js with content type ='application/x-www-form-urlencoded' 如何在节点js中使用参数为application / x-www-form-urlencoded类型的POST调用 - How to consume POST call where parameter is of type application/x-www-form-urlencoded in node js node.js正文解析器对Content-Type:x-www-form-urlencoded和Form-data JSON的错误解释 - node.js body-parser bad interpretation of Content-Type:x-www-form-urlencoded and Form-data JSON 使用“Content-Type”:“application/x-www-form-urlencoded”从 axios 发送帖子请求会给出 401 Unauthorized 响应 - Sending post request from axios with "Content-Type" : "application/x-www-form-urlencoded" gives an 401 Unauthorized response 如何解码使用x-www-form-urlencoded编码的Javascript对象数组? - How to decode array of Javascript object encoded with x-www-form-urlencoded? 使用 apollo-datasource-rest 库将 Content-Type 标头设置为 application/x-www-form-urlencoded - Setting Content-Type header to application/x-www-form-urlencoded using apollo-datasource-rest library Angular $ HTTP可与CORS和application / x-www-form-urlencoded一起使用,但可通过application / json获得OPTIONS 404 - Angular $HTTP works with CORS and application/x-www-form-urlencoded but gets OPTIONS 404 with application/json
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM