为了账号安全,请及时绑定邮箱和手机立即绑定

weex POST请求web端body服务器获取不到参数

weex POST请求web端body服务器获取不到参数

jeck猫 2018-10-05 12:07:11
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;  });
查看完整描述

2 回答

?
浮云间

TA贡献1829条经验 获得超3个赞

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;

  });


查看完整回答
反对 回复 2018-10-21
?
犯罪嫌疑人X

TA贡献2080条经验 获得超4个赞

在请求头中加入 "Content-Type": 'application/x-www-form-urlencoded;即可

查看完整回答
反对 回复 2018-10-21
  • 2 回答
  • 0 关注
  • 934 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信