1
I’m making a requisition with axios
with the verb post
, but I’m not getting it.
Note> With the verb get
I can do the requisition.
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;
}
Addressentity
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 http://localhost:62748/api/client: 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:8080' is therefore not allowed access.
Sopt colleague! Translate here!
– rbz