Search code examples
delphipostdelphi-xeindymultipartform-data

Indy adds = at every 72nd char with Multi part form data Post


With Delphi XE and Indy, I got some code which submits to a web form.

idhttp := TidHttp.create;
postData := TIdMultiPartFormDataStream.Create;
try
    postData.AddFormField('name', edName.text);
    postData.AddFormField('email', edEmail.txt);
    postData.AddFormField('description', mDescription.text);

    idhttp.Request.ContentType := 'Content-Type: multipart/form-data; boundary=' + postData.Boundary;
    idhttp.fHttp.Post('http://www.example.com/contact.php', postData);

    ShowMessage('Thank you for your contact us.');
finally
    postData.Free;
    idHttp.Free;
end;

However, when I enter something likes this in the description memo.

This is a really long descriptie piece of text so we can see just how it's wrapping these lines and what it's doig to them I think it's making a hash of it.

Argh waht a pain.

I get

This is a really long descriptie piece of text so we can see just how =
it's wrapping these lines and what it's doig to them I think it's maki=
ng a hash of it.

Argh waht a pain.

So it seems to be word wrapping for me, with = Anyone with any clues?


Solution

  • What you see is correct behavior. The TIdFormDataField.ContentTransfer property defaults to quoted-printable for text fields. That is exactly the type of encoding you are seeing being generated. In quoted-printable, a sole = character followed by a line break is called a "soft" break. It is how MIME breaks up long lines of text to fit within line length restrictions in various protocols, such as email.

    You can change the ContentTransfer property to any of the following supported values:

    • a blank string
    • 7bit
    • 8bit
    • binary
    • quoted-printable
    • base64

    If you do not want your text to be encoded, then set the ContentTransfer property to any of the values other than quoted-printable or base64.