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. docker-machine添加一個已有的docker主機(jī)問題2. docker綁定了nginx端口 外部訪問不到3. node.js - nodejs debug問題4. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個是怎么回事????5. docker - 如何修改運行中容器的配置6. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?7. docker網(wǎng)絡(luò)端口映射,沒有方便點的操作方法么?8. docker-compose中volumes的問題9. golang - 用IDE看docker源碼時的小問題10. debian - docker依賴的aufs-tools源碼哪里可以找到???
