Delphi DLL
Delphi DLL
URL-Encode a MIME Body
See more MIME Examples
Demonstrates the Chilkat Mime.UrlEncodeBody method, which replaces the current body with an application/x-www-form-urlencoded-style representation using the named charset. The only argument is the charset; it is a void method.
Background: This transforms the body into the form-encoding used by HTML form submissions — spaces to
+, reserved characters to percent-escapes — interpreting the text through the given charset first so non-ASCII characters encode correctly. It is a niche operation for constructing form-style payloads within a MIME part.Chilkat Delphi DLL Downloads
var
success: Boolean;
mime: HCkMime;
encodedBody: PWideChar;
begin
success := False;
// Demonstrates the Mime.UrlEncodeBody method, which replaces the current body with an
// application/x-www-form-urlencoded representation using the named charset. The only argument is
// the charset. It is a void method.
mime := CkMime_Create();
success := CkMime_SetBodyFromPlainText(mime,'name=John Doe & city=New York');
if (success = False) then
begin
Memo1.Lines.Add(CkMime__lastErrorText(mime));
Exit;
end;
// URL-encode the body: spaces become "+", reserved characters become %-escapes.
CkMime_UrlEncodeBody(mime,'utf-8');
encodedBody := CkMime__getBodyDecoded(mime);
if (CkMime_getLastMethodSuccess(mime) = False) then
begin
Memo1.Lines.Add(CkMime__lastErrorText(mime));
Exit;
end;
Memo1.Lines.Add(encodedBody);
CkMime_Dispose(mime);