class Url extends Object
Percent-encoding, as URLs and form bodies use it. Both methods are called on the class itself; a Url object is never constructed.
The class is exported by the KS module:
#Import "Ks" { Url }
Percent-encodes text.
Text := Url.Encode(Text , Encoding := "UTF-8")
Type: String
The text to encode.
Type: String
The encoding the text's bytes are taken in, named as for FileEncoding. It defaults to UTF-8. A name which cannot be resolved throws a ValueError.
Type: String
Returns the text with every byte outside the RFC 3986 unreserved set — A-Z a-z 0-9 - . _ ~ — percent-encoded. For example, Url.Encode("ä") returns %C3%A4, and Url.Encode("ab", "UTF-16") returns a%00b%00. A space becomes %20.
Resolves percent-escapes.
Text := Url.Decode(Text , Encoding := "UTF-8")
Type: String
The text to decode.
Type: String
The encoding the escaped bytes are read in, named as for FileEncoding. Defaults to UTF-8.
Type: String
Returns the decoded text.
A % which is not followed by two hexadecimal digits, and a +, are left unchanged.
#Import "Ks" { Url }
Url.Encode("a b&c=d") ; "a%20b%26c%3Dd"
Url.Decode("a%20b%26c") ; "a b&c"
Url.Decode("100%") ; "100%" — a lone % stands for itself
Builds a request URL with an encoded query value:
#Import "Ks" { Http, Url }
Res := Http.Get("https://example.com/search?q=" Url.Encode(Query))