javascript - weex POST請求web端body服務(wù)器獲取不到參數(shù)
問題描述
POST請求服務(wù)器取不到參數(shù),發(fā)現(xiàn)Stream.fetch采用的是直接將body變成字符串專遞給服務(wù)器,而我們的服務(wù)器需要的像Jquery那個樣的Ajax請求(&key=value)的形式,在charles攔截的到參數(shù)在request中為key值,而jquery中得到的是keyValue樣式,請問在哪個文件里面修改提交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:在請求頭中加入 '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. mysql - 表名稱前綴到底有啥用?2. 致命錯誤: Class ’appfacadeTest’ not found3. 老師們php,插入數(shù)據(jù)庫mysql,都是空的,要怎么解決4. 求大神支招,php怎么操作在一個html文件的<head>標(biāo)記內(nèi)添加內(nèi)容?5. php點(diǎn)贊一天一次怎么實(shí)現(xiàn)6. 怎么php怎么通過數(shù)組顯示sql查詢結(jié)果呢,查詢結(jié)果有多條,如圖。7. PHP類屬性聲明?8. sql語句 - 如何在mysql中批量添加用戶?9. phpstady在win10上運(yùn)行10. 在應(yīng)用配置文件 app.php 中找不到’route_check_cache’配置項(xiàng)
