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 - 新组成的数组打印出来出现问题,里面有对象,但长度为空2. docker网络端口映射,没有方便点的操作方法么?3. docker绑定了nginx端口 外部访问不到4. Docker for Mac 创建的dnsmasq容器连不上/不工作的问题5. macos - mac下docker如何设置代理6. angular.js - angular内容过长展开收起效果7. dockerfile - 为什么docker容器启动不了?8. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?9. angular.js使用$resource服务把数据存入mongodb的问题。10. docker-compose 为何找不到配置文件?

网公网安备