I am trying to register a user via the web api using Angular 2. My call is as follows:
this.http.post('http://localhost/Authenticated/api/account/register', JSON.stringify(this.cred)).subscribe(function (data) {
console.log(data);
});
My form is defined:
<form id="userData" (submit)="submitForm()">
<input type="text" name="userName" placeholder="Name" [(ngModel)]="cred.userName" />
<input type="password" name="password" placeholder="Password" [(ngModel)]="cred.password"/>
<input type="password" name="confirmPassword" placeholder="Password" [(ngModel)]="cred.confirmPassword"/>
<input type="submit" id="register" value="Register" />
</form>
When I make a post I am getting an HTTP415 error:
HTTP415: UNSUPPORTED MEDIA TYPE - The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method.
It depends on your web API mostly for login/register we post form data with this Content-Type Content-Type: application/x-www-form-urlencoded, otherwise you can use Content-Type: application/json.