tiqui_loquito
25-07-2020, 03:14:13
Buenas noches
Estoy usando:
Delphi 7
Indy 10.0.52
Y trato de realizar una conexión post a un servicio a través de un usuario y una contraseña, pero me sale el error 400 Bad Request
el código es:
procedure TForm1.Button3Click(Sender: TObject);
var
sResponse,url,Json: string;
JsonToSend: TStringStream;
HTTP1: TIdHTTP;
begin
Json:='{"estado": "Exito"}';
url:= 'http://54.39.180.178:8087/app_dev.php/cuenta/login';
JsonToSend := TStringStream.Create(Utf8Encode(Json)); // D2007 and earlier only
//in D2009 and later, use this instead:
try
HTTP1 := TIdHTTP.Create;
HTTP1.Request.Clear;
HTTP1.HandleRedirects := True;
HTTP1.ReadTimeout := 5000;
// HTTP1.Request.Accept := 'application/json';
HTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
HTTP1.Request.ContentEncoding := 'utf-8';
HTTP1.Request.BasicAuthentication := True;// FBasicByDefault
// HTTP1.Request.Authentication := TIdBasicAuthentication.Create;
HTTP1.Request.Username := 'SITIS';
HTTP1.Request.Password := 'a@a';
try
sResponse := HTTP1.Post(url,JsonToSend) ;
except
on E: Exception do
ShowMessage('Error on request: '#13#10 + e.Message);
end;
finally
JsonToSend.Free;
end;
end;
hago la pruebas con postmant y funciona (adjunto imagen), pero no se que me falta en el código.
agradezco su ayuda.
Estoy usando:
Delphi 7
Indy 10.0.52
Y trato de realizar una conexión post a un servicio a través de un usuario y una contraseña, pero me sale el error 400 Bad Request
el código es:
procedure TForm1.Button3Click(Sender: TObject);
var
sResponse,url,Json: string;
JsonToSend: TStringStream;
HTTP1: TIdHTTP;
begin
Json:='{"estado": "Exito"}';
url:= 'http://54.39.180.178:8087/app_dev.php/cuenta/login';
JsonToSend := TStringStream.Create(Utf8Encode(Json)); // D2007 and earlier only
//in D2009 and later, use this instead:
try
HTTP1 := TIdHTTP.Create;
HTTP1.Request.Clear;
HTTP1.HandleRedirects := True;
HTTP1.ReadTimeout := 5000;
// HTTP1.Request.Accept := 'application/json';
HTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
HTTP1.Request.ContentEncoding := 'utf-8';
HTTP1.Request.BasicAuthentication := True;// FBasicByDefault
// HTTP1.Request.Authentication := TIdBasicAuthentication.Create;
HTTP1.Request.Username := 'SITIS';
HTTP1.Request.Password := 'a@a';
try
sResponse := HTTP1.Post(url,JsonToSend) ;
except
on E: Exception do
ShowMessage('Error on request: '#13#10 + e.Message);
end;
finally
JsonToSend.Free;
end;
end;
hago la pruebas con postmant y funciona (adjunto imagen), pero no se que me falta en el código.
agradezco su ayuda.