Ir al contenido


Foto

error HTTP/1.0 400 Bad Request con TIdHTTP


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 tiquinho

tiquinho

    Member

  • Miembros
  • PipPip
  • 36 mensajes

Escrito 24 julio 2020 - 02:47

Buenas tardes a todos

 

tengo un problema cuando intento conectarme a un servicio REST

 

El error es HTTP/1.0 400 Bad Request

 

Este es el código:


php
  1. var
  2.  
  3. sResponse,url: string;
  4. JsonToSend: TStringStream;
  5. HTTP1: TIdHTTP;
  6.  
  7. begin
  8.  
  9. url:= 'http://54.39.180.178:8087/app_dev.php/cuenta/login';
  10.  
  11. JsonToSend := TStringStream.Create(Utf8Encode(Json)); // D2007 and earlier only
  12. //in D2009 and later, use this instead:
  13.  
  14. try
  15. HTTP1 := TIdHTTP.Create;
  16. HTTP1.Request.Clear;
  17. HTTP1.HandleRedirects := True;
  18. HTTP1.ReadTimeout := 5000;
  19. HTTP1.Request.ContentType := 'application/x-www-form-urlencoded';
  20. HTTP1.Request.ContentEncoding := 'utf-8';
  21. HTTP1.Request.BasicAuthentication := True;// FBasicByDefault
  22.  
  23. HTTP1.Request.BasicAuthentication := True;
  24. HTTP1.Request.Authentication := TIdBasicAuthentication.Create;
  25. HTTP1.Request.Authentication.Username := 'SITIS';
  26. HTTP1.Request.Authentication.Password := 'a@a';
  27.  
  28. try
  29. sResponse := HTTP1.Post(url,JsonToSend) ;
  30. except
  31. on E: Exception do
  32. ShowMessage('Error on request: '#13#10 + e.Message);
  33. end;
  34. finally
  35. JsonToSend.Free;
  36. end;

cuando ejecuta el post me sale el error, no se que me falta configurar.

 

Si lo hago por el postmart me funciona. Les adjunto la imagen

 

Agradezco la ayuda que me puedan aportar


  • 0




IP.Board spam blocked by CleanTalk.