7
I did a test using a method this way, test using the Postman is worked, wondered if this way I might have any problem.
in the Controller
//http://localhost:1608/api/ApiGuiaCidade/cadastrar/cliente/jose/02-02-2015/[email protected]/124546
[HttpPost]
[Route("cadastrar/cliente/{nome}/{datanascimento}/{email}/{senha}")]
public HttpResponseMessage clienteCadastro(string nome,DateTime datanascimento,string email,string senha)
{
try
{
var tCliente = new ClienteAplicacao();
tCliente.Inseri(nome,datanascimento,email,senha);
return Request.CreateResponse(HttpStatusCode.OK, "Cadastro do cliente " + nome + " realizado.");
}
catch (Exception ex )
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
in the application:
public void Inseri(string nome, DateTime datanascimento, string email, string senha)
{
var strQuery = "";
strQuery += "INSERT INTO CLIENTES (NOME, DATA_NASCIMENTO,EMAIL, SENHA)";
strQuery += string.Format(" VALUES ('{0}','{1}','{2}','{3}' )", nome, datanascimento, email, senha);
using (contexto = new Contexto())
{
contexto.ExecutaComando(strQuery);
}
}
I use it like this too.
– RBoschini
By chance you are using Entity Framework?
– Randrade
I don’t think this is the best practice, imagine the size of the url when you pass 50 or more fields as parameter. I also think that you do not want to pass password as plain text. The correct is to pass the values by
JSON
,XML
, etc and then deserialize .– rubStackOverflow
@Randrade I am not using Entity Framework
– Harry
I think you can do SQL Injection with this code, another point, method name as far as I know, are action verbs... in your case it would be INSERT and not INSERT... but it’s just a small detail.
– PauloHDSousa
@Paulohdsousa , I made the name change to INSERT, you’re right about SQL Injection, but the person would have to know the exact path to it, how I’m going to use for mobile so I think it gets more complicated
– Harry
You cannot send a JSON or XML like @rubStackOverflow said?
– PauloHDSousa