当前位置: 动力学知识库 > 问答 > 编程问答 >

node.js - Different array parse behaviour of x-www-form-urlencoded between ExpressJS and rails

问题描述:

I use content-type: application/x-www-form-urlencoded to send POST request to backend server. The post body as follow:

listing[pictures][files][][name]=9ADDD7B1-FCFF-4538-916A-1E63DFB43A72&

listing[pictures][files][][name]=EFFE67B2-5D41-4B74-A33E-5963F54FAEC7&

listing[pictures][files][][name]=BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5

In backend server, if I use ruby on rails, the POST will be parsed as follow:

"pictures"=>{

"files"=>[

{"name"=>"9ADDD7B1-FCFF-4538-916A-1E63DFB43A72"},

{"name"=>"EFFE67B2-5D41-4B74-A33E-5963F54FAEC7"},

{"name"=>"BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5"}

]

}

This result is what I expected to be.

But, If I use nodeJS express and body-parser:

// parse application/json

app.use(bodyParser.json());

// parse application/x-www-form-urlencoded

app.use(bodyParser.urlencoded({ extended: true }));

The POST will be parsed as follow:

"pictures"=>{

"files"=>[

"name"=>[

"9ADDD7B1-FCFF-4538-916A-1E63DFB43A72",

"EFFE67B2-5D41-4B74-A33E-5963F54FAEC7",

"BBC9CB38-FE01-4F1A-AE37-7ED71F4B2CB5"

]

]

}

So, my question is how can I get the same POST result in nodeJS?

分享给朋友:
您可能感兴趣的文章:
随机阅读: