Http.post issue while installupgrade CLI from v.2.x to v.3.1.3

plugins

#1

Hi, anyone experienced issue of executing http.post calls in a data.service under ns-cli v3.1.3? question is, have no problem call the same service by post call from postman and a webclient, even have no problem same code was working under ns-cli v.2.x, issue starts after upgrade to ns-cli v.3.1.3

here is the code
const headers = new Headers({ “Content-Type” : “application/json” });
const options = new RequestOptions({ headers: headers });
this.http.post(this.baseUrl + “api/test”, newProductObj, options)
.subscribe((res: any) => res.json())
.catch(this.handleError)

no error, but, no data insert into mongoodb when tap the button on a android device.

any idea?

thanks

Edit:
The above code is working perfectly in a webclient to call the service,
but above code is not return product data when calling service from an android device.

Try to use toPromise()
but, I am getting “_isScalar”: false from returned object

here are the code

component.ts
onItemTap(args) {
this.myService.(this.model)
.then((res: any) => res.json())
.(err: any) => console.log(err)); //{"_isScalar":false}
}

myService.postDataWithPromise
const headers = new Headers({ “Content-Type” : “application/json” });
const options = new RequestOptions({ headers: headers });
return this.http.post(
this.baseUrl + “api/test”, newProductObj, options).toPromise()
.then((res: Response) => res.json())
.catch(this.handleError)
}

not sure what is happening when calling from an android device to fetch the service data?


#2

Hey @wklkelin please consider adding promise resolution/rejection callbacks to the http.post call to make sure you aren’t missing any response from the server.


#3

to avoid the isScalar issue, you need to add a .map() to the this.http.post(). i would also move the .subscribe() to the line that calls the function instead