Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- 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.
local mime = chilkat.Mime.new()
local success = mime:set_body_from_plain_text("name=John Doe & city=New York")
if not success then
print(mime.last_error_text)
return
end
-- URL-encode the body: spaces become "+", reserved characters become %-escapes.
mime:url_encode_body("utf-8")
local encodedBody = mime:get_body_decoded()
if not mime.last_method_success then
print(mime.last_error_text)
return
end
print(encodedBody)