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!
. but why did not the paras display on the body? it still happened. thank you.