search

Home  >  Q&A  >  body text

javascript - weex POST request web-side body server cannot obtain parameters

The POST request server cannot get the parameters. It is found that Stream.fetch uses the method of directly turning the body into a string and passing it to the server. Our server requires an Ajax request (&key=value) like Jquery. The parameter intercepted by Charles is the key value in the request, but the keyValue style is obtained in jquery. In which file should I modify the method of submitting the 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;
  });
世界只因有你世界只因有你2741 days ago1626

reply all(2)I'll reply

  • 扔个三星炸死你

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

    Add "Content-Type": 'application/x-www-form-urlencoded; to the request header

    reply
    0
  • 女神的闺蜜爱上我

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

    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;
      });

    reply
    0
  • Cancelreply