I am making a request with axios
with the verb post
, but I can not.
Note > With the verb get
I can make the request.
Object
cliente: {
nomeCompleto: '',
cpf: '',
email: '',
endereco: {
cep: '',
logradouro: '',
localidade: '',
bairro: '',
uf: ''
}
}
Request
axios.post('http://localhost:62748/api/cliente', this.cliente)
.then(response => {
console.log(response)
})
.catch(function(error) {
console.log(error)
})
API
[HttpPost]
public void Post(
[FromBody] Cliente cliente, [FromServices] ClienteRepository _repository) {
_repository.Add(cliente);
}
Client Entity
public int ClienteId {
get;
set;
}
public string Cpf {
get;
set;
}
public string NomeCompleto {
get;
set;
}
public string Email {
get;
set;
}
public Endereco Endereco {
get;
set;
}
Address Entity
public int EnderecoId {
get;
set;
}
public string Cep {
get;
set;
}
public string Uf {
get;
set;
}
public string Localidade {
get;
set;
}
public string Bairro {
get;
set;
}
public string Logradouro {
get;
set;
}
Allow-Control-Allow-Origin in Startup.cs
and Configure
services.AddCors();
app.UseCors(builder => builder.WithOrigins("http://localhost:8080"));
Error
Failed to load link : Response to preflight request does not pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access.