In the BackEnd I have a method as follows:
[HttpPost, Route("api/usuario/novo")]
public void Post([FromBody]Usuario usuario)
{
_usuarioService.Adicionar(usuario);
}
That is, it is a Post method, which will receive a user and will add the same ...
In Angular I have the following requisition
inserindoUsuario(usuarios: any){
this.usuariosModel = {
UsuarioId: null,
Nome: usuarios.nome,
Sobrenome: usuarios.sobrenome,
Email: usuarios.email,
Senha: usuarios.senha,
Corretor: usuarios.corretor,
Contrato: usuarios.contrato
}
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.Http.post('http://localhost:57301/api/usuario/novo', JSON.stringify(this.usuariosModel), { headers: headers })
.subscribe(() => {
console.log(this.usuariosModel);
});
}
That is, I create a user, I add the Header of the request and I call Subscribe ... But in the browser console it presents the following error:
Failed to load http://localhost:57301/api/usuario/novo: Response to
preflight request doesn't pass access control check: No 'Access-
Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:4200' is therefore not allowed access. The
response had HTTP status code 405.
But my Header is already set up.