Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  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.

set mime = Server.CreateObject("Chilkat.Mime")

success = mime.SetBodyFromPlainText("name=John Doe & city=New York")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

'  URL-encode the body: spaces become "+", reserved characters become %-escapes.
mime.UrlEncodeBody "utf-8"

encodedBody = mime.GetBodyDecoded()
If (mime.LastMethodSuccess = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( mime.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( encodedBody) & "</pre>"

%>
</body>
</html>