首頁  >  問答  >  主體

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;
  });
世界只因有你世界只因有你2663 天前1570

全部回覆(2)我來回復

  • 扔个三星炸死你

    扔个三星炸死你2017-07-05 11:07:14

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

    回覆
    0
  • 女神的闺蜜爱上我

    女神的闺蜜爱上我2017-07-05 11:07:14

    stream.fetch({

    雷雷

    回覆
    0
  • 取消回覆