Ver Mensaje Individual
  #5  
Antiguo 31-10-2008
azulin azulin is offline
Miembro
 
Registrado: sep 2008
Posts: 13
Reputación: 0
azulin Va por buen camino
Ya he visto donde estaba el error. Indy 10 es ligeramente distinto a 9. Aqui está el código, probado con Turbo Delphi 2006:

Código:
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPServer, IdHTTPServer,
  StdCtrls, StrUtils, IdCustomHTTPServer, IdContext;
 
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  IdHTTPServer1: TIdHTTPServer;

implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
  IdHTTPServer1 := TIdHTTPServer.Create;
  IdHTTPServer1.DefaultPort := 8080;
  IdHTTPServer1.OnCommandGet := IdHTTPServer1CommandGet;
  IdHTTPServer1.Active := True;
end;
 
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  strHtml: String;
begin
  // respond
  strHtml := '<h1>Servidor DEMO</h1>' +
    '<p>This is the only page you''ll get from this example.</p><hr>' +
    '<p>Request: ' + ARequestInfo.Document + '</p>' +
    '<p>Host: ' + ARequestInfo.Host + '</p>' +
    '<p>Params: ' + ARequestInfo.UnparsedParams + '</p>' +
    '<p>The headers of the request follow: <br>' +
    ARequestInfo.RawHeaders.Text + '</p>';
  AResponseInfo.ContentText := strHtml;
end;
 

end.
Luego desde el navegador... http://127.0.0.1:8080/


Ahora tengo que ver como procesar la petición y en función de esta hacer algo.

Saludos!
Responder Con Cita