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. javascript - html5显示隐藏2. javascript - 如何用polymer写一个文件目录树?3. 如何解决Centos下Docker服务启动无响应,且输入docker命令无响应?4. angular.js - angularjs ng-repeat 不能刷新5. Angular.js 无法设置Authorization头,该怎么解决?6. angular.js - angular.ui:dropdown的下拉菜单关闭的偶尔失常问题7. css - 移动端 oppo 手机之 Border-radius8. 关于《Effective Java中文版(第2版)》的问题9. html - node.js中base标签中href的问题10. javascript - vue2.0中,$refs对象为什么用驼峰的方式获取不到属性?