I am new to angular 2, and I ran into a problem that I cannot find a solution to: When I try to send a message from angular 2 to the API, I get - 415 unsupported media type.
Angular 2 code:
onSubmit(value: any) { // console.log(value.message); let headers = new Headers({ 'Content-Type': 'application/json'}); let options = new RequestOptions({ headers: headers }); let creds = 'statusuknown'; let body = JSON.stringify(creds); this.http.post('http://localhost:1318/api/ActionItem', creds) .subscribe( () => {console.log('Success')}, err => {console.error(err)} ); }
And my controller code:
// POST api/actionitem [HttpPost] public ActionItem Post( [FromBody]string str)// _id, string _status) { ActionItem item = new ActionItem( 313, str); return item; }
when I change the controller code so as not to receive data from the body, it works, but refers to NULL.
My screenshot of the API call:
Please help and let me know if more information is needed.
source share