PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

UrlEncode

The UrlEncode function percent-encodes a given string so that reserved characters properly encoded with ‘%’ and two hexadecimal characters.

This is useful when formatting URLs for use with HttpService/GetAsync/HttpService/PostAsync, or POST data of the media type application/x-www-form-urlencoded (Enum/HttpContentType|Enum.HttpContentType.ApplicationUrlEncoded).

For instance, when you encode the URL:

http://robloxdev.com/api-reference/function/HttpService/UrlEncode

the function returns the string:

http%3A%2F%2Frobloxdev%2Ecom%2Fapi%2Dreference%2Ffunction%2FHttpService%2FUrlEncode

Parameters

Name Type Default Description

The string (URL) to encode

Returns

Return Type Summary

The encoded string


Code Samples


New Pastebin Post

Pastebin.com is a website that allows users to paste text (usually source code) for others to view publicly. This code sample uses HttpService PostAsync and the pastebin web API to automatically create a new public paste on the website. Since pastebin’s API is designed to take data in as a URL encoded string, the code uses a for-loop to turn the dataFields table into a URL encoded string, such as hello=world&foo=bar. This is used as the HTTP POST data.

Test this code by first going to pastebin.com/api#1 and getting an API key (you’ll need a pastebin account to do this). Then, paste your unique developer API key into the field api_dev_key in the code sample’s dataFields table. Fill in any other information about the post you want to make, then run this code in a Script (not a LocalScript). If all goes well, you’ll get a URL to your new paste in the Output window (or some error string from pastebin).


HttpService UrlEncode

This code sample uses UrlEncode to turn a string into a safe, percent-encoded string that can be used in a URL as an argument. Notice how only unreserved characters (letters, numbers and -_.~) are not transformed into percent-encoded equivalents. Characters with accents are also transformed (for example é is transformed into %C3).