Skip to content

Instantly share code, notes, and snippets.

@bartwttewaall
Created July 22, 2019 08:01
Show Gist options
  • Save bartwttewaall/1bce3c036f4e1bd1da3ec08a6079ec53 to your computer and use it in GitHub Desktop.
Save bartwttewaall/1bce3c036f4e1bd1da3ec08a6079ec53 to your computer and use it in GitHub Desktop.
When you need to send a string to a backend but some characters are missing, chance is you need to URLEncode it

UrlEncoding

Sending a string over to the colyseus server through a Dictionary<string, object> can result in missing characters.

var options = new Dictionary<string, object> () {
  { "sessionTicket", WebUtility.UrlEncode(sessionTicket) }
};
room = client.Join<SK.Schemas.PvpGameState> (roomId, options);

The following code snippet is showing us the difference between encodeURIComponent and HttpUtility.UrlEncode. Encoding the following string: ~!@#$%^&*(){}[]=:/,;?+'"\ HttpUtility.UrlEncode result: %7e!%40%23%24%25%5e%26*()%7b%7d%5b%5d%3d%3a%2f%2c%3b%3f%2b%27%5c Javascript's encodeURIComponent result: ~!%40%23%24%25%5E%26*()%7B%7D%5B%5D%3D%3A%2F%2C%3B%3F%2B'%22%5C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment