testcgi.pp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. {$mode objfpc}
  2. {$H+}
  3. program testcgi;
  4. uses cgiapp,classes,sysutils;
  5. Type
  6. TTestCGI = Class(TCGIApplication)
  7. Procedure DoRun; override;
  8. end;
  9. Procedure TTestCGI.DoRun;
  10. Var
  11. L : TStrings;
  12. I: Integer;
  13. begin
  14. ContentType:='text/html';
  15. EmitContentType;
  16. L:=TStringList.Create;
  17. Writeln('<HTML><TITLE>',title,'</TITLE><BODY>');
  18. Try
  19. Writeln('<H1>List of CGI variables:</H1>');
  20. GetCGIVarList(L);
  21. For I:=0 to L.Count-1 do
  22. Writeln(L[i],'<BR/>');
  23. Writeln('<H1>List of environment variables:</H1>');
  24. GetEnvironmentList(L);
  25. For I:=0 to L.Count-1 do
  26. Writeln(L[i],'<BR/>');
  27. If (RequestVariableCount>0) then
  28. begin
  29. Writeln('<H1>List of form variables:</H1>');
  30. GetRequestVarList(L);
  31. For I:=0 to L.Count-1 do
  32. Writeln(L[i],'<BR/>');
  33. Writeln('<H1>List of form variables, tabular format:</H1>');
  34. Writeln('<table width="100%" border="1">');
  35. Writeln('<TR><TH>Name</TH><TH>Value</TH></TR>');
  36. GetRequestVarList(L,True);
  37. For I:=0 to L.Count-1 do
  38. Writeln('<TR><TD>',L[i],'</TD><TD>',RequestVariables[L[i]],'</TD></TR>');
  39. end;
  40. Finally
  41. Writeln('</BODY></HTML>');
  42. Terminate;
  43. end;
  44. end;
  45. begin
  46. With TTestCGI.Create(Nil) do
  47. Try
  48. Title:='Test CGI application';
  49. Initialize;
  50. Run;
  51. Finally
  52. Free;
  53. end;
  54. end.