I am currently developing an app in ionic v3 within visual studio (Tools for Apache Cordova). On one of the screens in my app, I gather user information and send it to an API. However, I'm encountering an issue with the HTTP POST request that I'm making - it's not functioning as expected. Oddly enough, when I test the same request using Postman, it works perfectly fine.
Despite trying various solutions found online, none have resolved my problem. One attempt involved modifying the header passed along with the request by including 'user-agent'.
let header = new Headers({
'Content-Type': 'application/json; charset=utf-8',
'Authorization': 'console',
'MacAddress': localStorage.getItem('macAddress'),
'Key': localStorage.getItem('key'),
'access-control-allow-origin': '*',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'
});
let data = JSON.stringify({
FirstName: this.FirstName,
LastName: this.LastName,
MI: this.u_mname,
Address: this.Address,
City: this.City,
State: this.State,
ZipCode: this.ZipCode,
HomePhone: this.HomePhone,
OfficePhone: this.OfficePhone,
OfficePhoneExt: this.OfficePhoneExt,
CellPhone: this.CellPhone,
Fax: this.Fax,
Email1: this.Email1,
Email2: this.Email2,
ContactTypeId: this.ContactTypeId,
dob: this.dob,
ApplicationId: this.ApplicationId
});
this.http.post(localStorage.getItem('base_url') + '/services/odata/tblContacts?Mother=0&Father=0&Guardian=0&groupIdList=0', data, { headers: header})
.map(res => console.log(res))
.subscribe(
data => {
alert(data)
}, err => {
alert(err)
})
My anticipation was to receive a 'HTTP status code 201' as a response, however, what I get is a status code of 200 along with the message 'Internal Server Error. Please see details on server logs.'