TidHTTP Post bug or misuse?

Giganews Newsgroups
Subject: TidHTTP Post bug or misuse?
Posted by:  Jérémy Reynaud (…@keepcore.com)
Date: Fri, 11 Aug 2006

Dear all,

I have a problem with the TIdHTTP Post function.
To resume, using TStringList to post variables works fine. But if I use it
after using TIdMultiPartFormDataStream to post, it doesn't work anymore...

To isolate the problem, I create a simple application with 2 buttons, 1 to
post with TStringList, the other to post with TIdMultiPartFormDataStream,
the response is logged in a TMemo. The URL is a PHP page that print the
content of the $_POST variable (print_r($_POST);).

When I click on the 1st button (TStringList), I have this in the TMemo:
Array
(
    [PostVar1] => TStringList - Test1
    [PostVar2] => TStringList - Test2
)

When I click on the 2nd one (TIdMultiPartFormDataStream ), I have this in
the TMemo:
Array
(
    [PostVar1] => TIdMultiPartFormDataStream - Test1
    [PostVar2] => TIdMultiPartFormDataStream - Test2
)

If I click again on the 1st one, I have:
Array
(
)

Seems no more variables are posted...
Please, could you help me? Is it a bug or a misuse of the component?
Thanks.

Jérémy

Here is the code of both buttons:
procedure TForm1.ButtonPostStringsClick(Sender: TObject);
var
  aPostStrings: TStringList;
  aResponse: string;
begin
  aPostStrings := TStringList.Create;
  try
    try
      aPostStrings.Add('PostVar1=TStringList - Test1');
      aPostStrings.Add('PostVar2=TStringList - Test2');
      aResponse := IdHttp1.Post(cTestpage, aPostStrings);
      Memo1.Lines.Text := aResponse;
    except
      on E:Exception do
      begin
        MessageDlg(E.ClassName + ' exception in ButtonPostStringsClick:' +
E.Message,
          mtError, [mbOK], 0);
      end;
    end;
  finally
    aPostStrings.Free;
  end;
end;

procedure TForm1.ButtonPostDataStreamClick(Sender: TObject);
var
  aResponse: string;
  DataStrm: TIdMultiPartFormDataStream;
begin
  DataStrm := TIdMultiPartFormDataStream.Create;
  try
    try
      DataStrm.AddFormField('PostVar1', 'TIdMultiPartFormDataStream -
Test1');
      DataStrm.AddFormField('PostVar2', 'TIdMultiPartFormDataStream -
Test2');
      aResponse := IdHttp1.Post(cTestpage, DataStrm);
      Memo1.Lines.Text := aResponse;
    except
      on E:Exception do
      begin
        MessageDlg(E.ClassName + ' exception in ButtonPostStringsClick:' +
E.Message,
          mtError, [mbOK], 0);
      end;
    end;
  finally
      DataStrm.Free;
  end;
end;

Replies