javascript - weex POST请求web端body服务器获取不到参数
问题描述
POST请求服务器取不到参数,发现Stream.fetch采用的是直接将body变成字符串专递给服务器,而我们的服务器需要的像Jquery那个样的Ajax请求(&key=value)的形式,在charles拦截的到参数在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; });
相关文章:
1. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题2. mysql begin work语句是干嘛的?3. javascript - 移动端css动画播放状态暂停在ios不起作用 animation-play-state4. node.js - 函数getByName()中如何使得co执行完后才return5. javascript - vue $set 整个数组6. docker-compose中volumes的问题7. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?8. 小程序怎么加外链,语句怎么写!求救新手,开文档没发现9. 新手 - Python 爬虫 问题 求助10. javascript - vue+iview upload传参失败 跨域问题后台已经解决 仍然报403,这是怎么回事啊?
