I am using Ionic 4 to create a small mobile app. The back-end is C# WebAPI. I need to submit some data to the server. And it does not work.
The Code:
NewsDetails = {
"ServerID": "1",
"Title": "Test",
"Source": "Self",
"Body": "Hello world"
};
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
this.http.post("https://sitename.com/DataServer/News", this.NewsDetails, httpOptions)
.subscribe(data => {
this.router.navigateByUrl("/home/news");
}, (err) => {
console.error("unable to connect to server:", JSON.stringify(err));
});
The above code produces the following error:
{
"headers":{"normalizedNames":{},
"lazyUpdate":null,
"headers":{}},
"status":0,
"statusText":"Unknown Error",
"url":"https://sitename.com/DataServer/News",
"ok":false,
"name":"HttpErrorResponse",
"message":"Http failure response for https://sitename.com/DataServer/News: 0 Unknown Error",
"error":{"isTrusted":true}
}
I tried updating the same from POSTMAN application and works fine. Any idea the reason for the error?
Thanking u in advance.