I have w big problem with request from angular 5 (localhost:4200) to my .NET Core WebApi (localhost:55007). I think I tried everything and all lost..
Situation looks: login.service.ts
import { Injectable, Inject } from '@angular/core';
import {HttpModule, Http, URLSearchParams, Headers, RequestOptions} from
'@angular/http';
@Injectable()
export class LoginService {
constructor( public http: Http) {
}
login(email:string, password:string){
this.http.post('http://localhost:55007/Login/Login',
{email:"fooad@ds.pl",password:"loqweqko"}).subscribe(
res => {
console.log(res);
},
(err) => {
console.log(err);
}
);
}
}
webApi method:
[Route("[controller]/[action]")]
public class LoginController : Controller
{
[HttpPost]
public object Login([FromBody] LoginDto model)
{
//something..
}
}
Where LoginDto is:
public class LoginDto
{
[Required]
public string Email { get; set; }
[Required]
public string Password { get; set; }
}
Please tell me what I'm doing wrong.. I have also tried use json.stringify as an object in request. Nothing happends.. I'm always getting 404.. (using postman all works correcty, also GET method works).
---------------------------EDIT---------------------------
Ok, I found solution - the problem was with CORS, I made the same as : How to enable CORS in ASP.net Core WebAPI
and for me works. Thanks :)