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. vue.js - vue apache 代理设置2. angular.js - 百度支持_escaped_fragment_吗?3. 我在centos容器里安装docker,也就是在容器里安装容器,报错了?4. node.js - Vue+Webpack在dev环境下没有问题build后出现莫名错误5. node.js - nodejs+express+vue6. javascript - 为什么js代码后面报错,会导致前面的代码执行不了,我确定后面的部分和前面的部分没有逻辑上的关联。7. 微信公众号实现消息模板的推送?8. css3 - 如图的flex骰子布局是怎么实现的?9. javascript - ios返回不执行js怎么解决?10. html - vue如何定义一个变量,让所有组件都能使用
