Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Delphi para la web (https://www.clubdelphi.com/foros/forumdisplay.php?f=51)
-   -   Delphi Error 400 Bad Reques HTTP Post JSON (https://www.clubdelphi.com/foros/showthread.php?t=94797)

tiqui_loquito 25-07-2020 03:14:13

Delphi Error 400 Bad Reques HTTP Post JSON
 
1 Archivos Adjunto(s)
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:

Código Delphi [-]
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.


La franja horaria es GMT +2. Ahora son las 12:18:50.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi