From explorer i get json code and displayed correctly
When I try to read from WebClientConnection1, I have no answer
From http://code.jsontest.com/, WebClientConnection1 writes the answer
WebApplication:
procedure TForm1.WebButton2Click(Sender: TObject);
begin
WebMemo1.Lines.Clear;
if WebClientConnection1.Active then WebClientConnection1.Active := false;
WebClientConnection1.URI := WebEdit1.Text; // 'http://code.jsontest.com/';
WebClientConnection1.Active := true;
end;
procedure TForm1.WebClientConnection1DataReceived(Sender: TObject;
ARequest: TJSXMLHttpRequestRecord; var AResponse: string);
begin
WebMemo1.Lines.Clear;
WebMemo1.lines.Add(AResponse);
end;
Server:
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}cthreads, cmem,{$ENDIF} sysutils, fphttpapp, httpdefs, httproute;
procedure timeEndpoint(req: TRequest; res: TResponse);
begin
res.Content := '{ "TMOV": [{ "codigo": "E", "descr": "Entrada" }, { "codigo": "S", "descr": "Salida" }'+
'], "SITS": [{"codigo": "1","descr": "Abierto"},{"codigo": "2", "descr": "En proceso"},{"codigo": "3",'+
'"descr": "Cerrado"}]}';
res.Code := 200;
res.ContentType := 'application/json';
res.CacheControl := 'private';
res.ContentLength := length(res.Content);
res.Date := DateToStr(now);
res.SendContent;
end;
begin
Application.Port := 8080;
HTTPRouter.RegisterRoute('/time', @timeEndpoint, true);
Application.Threaded := true;
Application.Initialize;
Application.Run;
end.