After downloading a project from the link provided by ASP.NET on individual accounts in Web API, I managed to run it successfully on VS2015 and IIS Express. However, my goal now is to utilize Angular 2 to call the API.
In order to achieve this, I set up a new project in Visual Studio Code using Angular 2 and TypeScript. Despite my efforts, when attempting to make a POST request to the API method called Register, all the values appear as null.
My Visual Studio Code service (Angular2)
import { Injectable } from 'angular2/core';
import { Account } from '../account/Account';
import { RegisterBindingModel } from '../account/RegisterBindingModel';
import {Http, Response, Headers, RequestOptions} from 'angular2/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class AccountService {
constructor(private _http: Http) {
}
createAccount(account: Account): Observable<string> {
console.log('accountService.createAccount');
let body = JSON.stringify({ account });
console.log('T1' + body);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this._http.post('https://localhost:44305/api/Account/Register', body, options)
.map(this.extractData)
.catch(this.handleError);
Issues faced in browser and POST values: https://i.sstatic.net/N7zvb.png
Error messages received from server API: https://i.sstatic.net/7Yx3O.png Error2_In_API_Method https://i.sstatic.net/MjgRz.png
While GET operations work fine, all my POST operations result in NULL values. What could be causing this issue?