javascript - weex POST請(qǐng)求web端body服務(wù)器獲取不到參數(shù)
問題描述
POST請(qǐng)求服務(wù)器取不到參數(shù),發(fā)現(xiàn)Stream.fetch采用的是直接將body變成字符串專遞給服務(wù)器,而我們的服務(wù)器需要的像Jquery那個(gè)樣的Ajax請(qǐng)求(&key=value)的形式,在charles攔截的到參數(shù)在request中為key值,而jquery中得到的是keyValue樣式,請(qǐng)問在哪個(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; });
問題解答
回答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. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?2. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!3. html5和Flash對(duì)抗是什么情況?4. javascript - QQ第三方登錄的問題5. 在mac下出現(xiàn)了兩個(gè)docker環(huán)境6. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. spring-mvc - spring-session-redis HttpSessionListener失效9. java - Spring boot 讀取 放在 jar 包外的,log4j 配置文件,系統(tǒng)有創(chuàng)建日志文件,不寫入日志信息。10. 淺談Vue使用Cascader級(jí)聯(lián)選擇器數(shù)據(jù)回顯中的坑

網(wǎng)公網(wǎng)安備