How to encode the plus (+) symbol in a URL
The +
character has a special meaning in a URL => it means whitespace -
. If you want to use the literal +
sign, you need to URL encode it to %2b
:
body=Hi+there%2bHello+there
Here's an example of how you could properly generate URLs in .NET:
var uriBuilder = new UriBuilder("https://mail.google.com/mail");var values = HttpUtility.ParseQueryString(string.Empty);values["view"] = "cm";values["tf"] = "0";values["to"] = "someemail@somedomain.com";values["su"] = "some subject";values["body"] = "Hi there+Hello there";uriBuilder.Query = values.ToString();Console.WriteLine(uriBuilder.ToString());
The result
In order to encode +
value using JavaScript, you can use encodeURIComponent
function.
Example:
var url = "+11";var encoded_url = encodeURIComponent(url);console.log(encoded_url)