javascript - weex POST請(qǐng)求web端body服務(wù)器獲取不到參數(shù)
問(wèn)題描述
POST請(qǐng)求服務(wù)器取不到參數(shù),發(fā)現(xiàn)Stream.fetch采用的是直接將body變成字符串專(zhuān)遞給服務(wù)器,而我們的服務(wù)器需要的像Jquery那個(gè)樣的Ajax請(qǐng)求(&key=value)的形式,在charles攔截的到參數(shù)在request中為key值,而jquery中得到的是keyValue樣式,請(qǐng)問(wèn)在哪個(gè)文件里面修改提交body的方式?
stream.fetch({
method: ’POST’, url: POST_URL, type:’json’,
//headers: {’Content-Type’: ’application/json; charset=utf-8’,},
body: JSON.stringify({ data: bodyString})//or you can just use JSON Object {username:’weex’} }, function(ret) { if(!ret.ok){ me.postResult = 'request failed'; }else{ console.log(’get:’+JSON.stringify(ret)); me.postResult = JSON.stringify(ret.data); } },function(response){ console.log(’get in progress:’+response.length); me.postResult = 'bytes received:'+response.length; });
問(wèn)題解答
回答1:在請(qǐng)求頭中加入 'Content-Type': ’application/x-www-form-urlencoded;即可
回答2:stream.fetch({
method: ’POST’, url: POST_URL, type:’json’, body:JSON.stringify({username:’weex’})//or you can just use JSON Object {username:’weex’} }, function(ret) { if(!ret.ok){ me.postResult = 'request failed'; }else{ console.log(’get:’+JSON.stringify(ret)); me.postResult = JSON.stringify(ret.data); } },function(response){ console.log(’get in progress:’+response.length); me.postResult = 'bytes received:'+response.length; });
相關(guān)文章:
1. windows誤人子弟啊2. mysql優(yōu)化 - MySQL如何為配置表建立索引?3. 實(shí)現(xiàn)bing搜索工具urlAPI提交4. 關(guān)于mysql聯(lián)合查詢(xún)一對(duì)多的顯示結(jié)果問(wèn)題5. 數(shù)據(jù)庫(kù) - Mysql的存儲(chǔ)過(guò)程真的是個(gè)坑!求助下面的存儲(chǔ)過(guò)程哪里錯(cuò)啦,實(shí)在是找不到哪里的問(wèn)題了。6. 我在網(wǎng)址中輸入localhost/abc.php顯示的是not found是為什么呢?7. 如何用筆記本上的apache做微信開(kāi)發(fā)的服務(wù)器8. python - linux怎么在每天的凌晨2點(diǎn)執(zhí)行一次這個(gè)log.py文件9. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)10. 冒昧問(wèn)一下,我這php代碼哪里出錯(cuò)了???
