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. angular.js - 不适用其他构建工具,怎么搭建angular1项目2. python如何不改动文件的情况下修改文件的 修改日期3. mysql - 一个表和多个表是多对多的关系,该怎么设计4. javascript - git clone 下来的项目 想在本地运行 npm run install 报错5. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?6. android-studio - Android 动态壁纸LayoutParams问题7. 主从备份 - 跪求mysql 高可用主从方案8. angular.js - 三大框架react、vue、angular的分析9. python 如何实现PHP替换图片 链接10. python - django 里自定义的 login 方法,如何使用 login_required()
