Re: TidHttp.Post, unable to retrieve the posted fields on webserver

Giganews Newsgroups
Subject: Re: TidHttp.Post, unable to retrieve the posted fields on webserver
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Mon, 21 Nov 2005

"Robert Ehrenhard" <r.ehrenha…@chello.nl> wrote in message
news:C1166CB194E2E240r.ehrenha…@chello.nl...

> The ASP page however does not receive/recognize
> the posted formfield(s)?

The Request.Forms collection of ASP cannot process "multipart/form-data"
values (which you should be using only for file uploads anyway).  If you
want to continue using "multipart/form-data" then you need to receive the
data manually using the Request.BinaryRead() method and then parse the MIME
data yourself.

Otherwise, don't use "multipart/form-data" in the first place (especially
since you are only sending a single value anyway which is not a file).  Use
"application/x-www-form-urlencoded" instead, ie:

    procedure TForm1.Button1Click(Sender: TObject);
    var
        PostData : TStringStream;
        ResponseData : TStringStream;
    begin
        try
            PostData := TStringStream.Create('formfield1=blablabla');
            try
                ResponseData := TStringStream.Create('');
                try
                    HTTP.Request.ContentType :=
'application/x-www-form-urlencoded';
                    HTTP.Post('http://www.somedomain.com/temp/xmlfile.asp',
PostData, ResponseData);
                    ShowMessage(ResponseData.DataString);
                finally
                    ResponseData.Free;
                end;
            finally
                PostData.Free;
            end;
        except
            on E: Exception do
                ShowMessage('Error encountered: ' + E.Message);
        end;
    end;

Alternatively:

    procedure TForm1.Button1Click(Sender: TObject);
    var
        PostData : TStringList;
        ResponseData : TStringStream;
    begin
        try
            PostData := TStringList.Create;
            try
                PostData.Values['formfield1'] := 'blablabla';
                ResponseData := TStringStream.Create('');
                try
                    HTTP.Request.ContentType :=
'application/x-www-form-urlencoded';
                    HTTP.Post('http://www.somedomain.com/temp/xmlfile.asp',
PostData, ResponseData);
                    ShowMessage(ResponseData.DataString);
                finally
                    ResponseData.Free;
                end;
            finally
                PostData.Free;
            end;
        except
            on E: Exception do
                ShowMessage('Error encountered: ' + E.Message);
        end;
    end;

Gambit

Replies

In response to

TidHttp.Post, unable to retrieve the posted fields on webserver posted by Robert Ehrenhard on Sun, 20 Nov 2005