[fpc-pascal] Troubles with CGI and POST content

Sven Barth svenmauren at vr-web.de
Sun Nov 15 12:45:55 CET 2009


Hello together!

I'm working on a little personal website and encountered a very strange =

problem with the content that is sent by a form:

I run the attached CGI test application on my webspace which is a x86_64 =

Linux. When I enter text which contains a certain amount of =

characters/bytes into the textarea and submit that form, a part of the =

content seems to be truncated (all zeros) - this includes the =

name-value-pair of the submit button (which is sent after the textarea) =

so that the submit is not detected. It doesn't matter if my application =

is compiled for i386 or x86_64.

The problem doesn't appear when I run the app on my local servers (i386 =

Linux and Windows).

This "magical amount" is reached earlier when I use multi byte =

characters (e. g. umlauts).

What can be the problem? Can it be a configuration problem of Apache? =

(all three computers run Apache) Or is it a problem because the webspace =

  has a different "library environment" than my local computers? (but =

the executable has no dependencies?!)

Regards,
Sven
-------------- next part --------------
program cgitest;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this }, custcgi, HTTPDefs, sysutils;

type
  TMyCGITest =3D class(TCustomCGIApplication)
    procedure handleRequest(ARequest: TRequest; AResponse: TResponse);
           override;
  end;

{ TMyCGITest }

procedure TMyCGITest.handleRequest(ARequest: TRequest; AResponse: TResponse=
);
var
  msg: String;
begin
  if ARequest.ContentFields.Values['button'] <> '' then
    msg :=3D 'This was a POST'
  else
    msg :=3D 'This was not a POST';

  AResponse.ContentType :=3D 'text/html; charset=3Dutf-8';
  AResponse.Content :=3D
    '<html>' +
    '<head><title>CGI Test</title><meta http-equiv=3D"content-type" content=
=3D"text/html; charset=3DUTF-8" /></head>' +
    '<body><p>' + msg + '</p><form method=3D"POST" action=3D"./cgitest" acc=
ept-charset=3D"UTF-8"><p><textarea rows=3D"15" cols=3D"80" name=3D"text">' =
+ ARequest.ContentFields.Values['text'] + '</textarea></p><p><input type=3D=
"submit" name=3D"button" value=3D"Send" /></form></body>' +
    '</html>';
end;

{$IFDEF WINDOWS}{.$R cgitest.rc}{$ENDIF}

var
  app: TMyCGITest;
begin
  app :=3D TMyCGITest.Create(Nil);
  try
    app.Initialize;
    app.Run;
  finally
    app.Free;
  end;
end.



More information about the fpc-pascal mailing list