Ionic 2 post did not request the endpoint with paras in the body


#1

i am try to insert a new record via webapi into database. and use http.post ,it did not send a request to sever and no error. i compare with recent post request code what work fine. i can not find any difference and clue. can someone help me ? thanks.

ride-data.ts service

  CreateRidePost(CarRide) {
    let headers = new Headers({
    'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    });
    // let headers = new Headers();
    // headers.append('Accept', 'application/json')
    // headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    // var token = localStorage.getItem('token');

    var token = this.storage.get('loginInfo').then((loginInfo) => {
      console.log('loginInfo: ' + loginInfo);

      console.log('-------CreateRidePost---------');
      var val = JSON.parse(loginInfo);
      //   console.log(val);
      console.log(val.LoginId);
      return val.Token;

    });
 
    if (token) {
      headers.append('Authorization', 'Bearer ' + token);

    }

    let options = new RequestOptions({
      headers: headers
    });
  console.log(CreateRideURL +" "+CarRide+" "+options);
    return     this.http.post(CreateRideURL, CarRide, options).subscribe(data=>{
    console.log(data['_body']);
    },error=>{
       console.log(error);
    })   
         
  }

 add-car.ts


addCarRide() {

    console.log("addCarRide");

    let departure = this.CarRide.Departure,
      rideType = this.CarRide.RideType,
      via = this.CarRide.Via,
      destination = this.CarRide.Destination,
      passengerNumber = this.CarRide.PassengerNumber,
      dueDateTime = this.CarRide.DueDate + " " + this.CarRide.DueTime,
      supplementaryNote = this.CarRide.SupplementaryNote
   // let body = JSON.stringify(ride);
    let CarRide = this.Utility.jsonToURLEncodedFormData({
      Departure: departure, RideType: rideType, Via: via, Destination: destination,
      PassengerNumber: passengerNumber, DueDateTime: dueDateTime, SupplementaryNote: supplementaryNote
    });  // urlencoded
//  let CarRide ={
//       Departure: departure, RideType: rideType, Via: via, Destination: destination,
//       PassengerNumber: passengerNumber, DueDateTime: dueDateTime, SupplementaryNote: supplementaryNote
//     };  // json
   console.log(CarRide);

   
       this.RideService.CreateRidePost(CarRide)

   

  }

here is the chrome console as below:


----AllCarsList END-------
VM385 main.js:47056 AddCarRide
VM385 main.js:32211 Hello RideService Provider
VM385 main.js:46526 Hello AddCarPage Page
VM385 main.js:46529 addCarRide
VM385 main.js:46540 Departure=1&RideType=1&Via=1&Destination=1&PassengerNumber=3&DueDateTime=2017-04-29T09%3A39%3A41.990Z%2000%3A00&SupplementaryNote=1
VM385 main.js:32298 http://localhost:58713/api/Ride/AddRideInfo Departure=1&RideType=1&Via=1&Destination=1&PassengerNumber=3&DueDateTime=2017-04-29T09%3A39%3A41.990Z%2000%3A00&SupplementaryNote=1 [object Object]

console.log(CreateRideURL +" “+CarRide+” "+options);
VM385 main.js:32298 http://localhost:58713/api/Ride/AddRideInfo Departure=1&RideType=1&Via=1&Destination=1&PassengerNumber=3&DueDateTime=2017-04-29T09%3A39%3A41.990Z%2000%3A00&SupplementaryNote=1 [object Object]


and i found this _
Departure=1&RideType=1&Via=1&Destination=1&PassengerNumber=3&DueDateTime=2017-04-29T09%3A39%3A41.990Z%2000%3A00&SupplementaryNote=1_
did not attach to the body and send to serve. this is the problem. i do not know how to fix this issure. need ur help!


#2

Please change your code so the output is relatable to the console.log - right now I have no idea which console.log caused which output. Also, please post only code that is relevant to the problem - I think all of addCarRide is not, correct?


#3

If this is iOS, I believe all endpoints must be https. One other problem is that your authorization header needs to be “Bearer”, not “Bear”.


#4

@ rapropos thank you .this is for Android OS. u reminded me another problem. :grin: . but why did not the paras display on the body? it still happened. thank you.