POST發(fā)送以下的數(shù)據(jù):
{
user_id:122,
need_data: [
};
{
"describe":"測試",
"img":"2017-09-28/59cccd5e7ef567.52312577.jpg,"
}
]
經(jīng)過測試.'application/json',不生效, 只有'application/x-www-form-urlencoded'生效,
而后臺只能收到
{
user_id:122,
need_data:[ Obejct Object ]
}
是我header不正確, 還是小程序POST根本不支持多級JSON 數(shù)據(jù)交互????
如果是我header不正確,那么請教下header如何設(shè)置, 后臺才能完全收到???
網(wǎng)友回復(fù):
@官方
來人啊
能不能把代碼貼全一點。
@官方,你看下
wx.request({
url:config.c.BuywouldLike,
method:"POST",
header: {"content-type":"application/x-www-form-urlencoded"},
data:{
user_id:122,
need_data;[ { "describe":"測試" , "img":"2017-09-28/59cccd5e7ef567.52312577.jpg," } ]
},
dataType:"JSON"
});
發(fā)到后臺后,need_data是字符串"[ Object Object ] "
wx.request({
url:config.c.BuywouldLike,
method:"POST",
header: {"content-type":"application/x-www-form-urlencoded"},
data:{
user_id:122,
need_data: JSON.stringify([ { "describe":"測試" , "img":"2017-09-28/59cccd5e7ef567.52312577.jpg," } ])
},
dataType:"JSON"
});
試試?
.'application/json',不生效
是因為你后臺只接受 application/x-www-form-urlencoded 的把?
二級json一定要轉(zhuǎn)字符串嗎,那POST還有什么用.....
你查下 application/x-www-form-urlencoded 是什么意思。
你這種其實用 application/json 是最合適的
- application/x-www-form-urlencoded: 數(shù)據(jù)被編碼成以 '&' 分隔的鍵-值對, 同時以 '=' 分隔鍵和值. 非字母或數(shù)字的字符會被 percent encoded:
application/json 在post下不生效啊,后臺也沒問題,
不過謝謝,我已經(jīng)改了結(jié)構(gòu)實現(xiàn)功能