Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode the plus (+) symbol in a URL

The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) signs in the email body with blank space. It looks like it only happens with the + sign. How can I remedy this? (I am working on a ASP.NET web page.)

https://mail.google.com/mail?view=cm&tf=0&[email protected]&su=some subject&body=Hi there+Hello there

(In the body email, "Hi there+Hello there" will show up as "Hi there Hello there")

like image 571
user523234 Avatar asked Mar 27 '11 15:03

user523234


People also ask

How do I encode a plus sign URL?

URL encoding normally replaces a space with a plus (+) sign or with %20.

Can you put a plus sign in a URL?

Generally speaking, the plus sign is used as shorthand for a space in query parameters, but while it can be used in such a way in URLs, it isn't a good idea. The plus sign is sometimes transformed into a space or to “%20” which can cause problems for the spiders crawling your site, hence causing issues with indexation.

How do you pass a plus sign in a URL query string?

Now, if you want a literal + to be present in the query string, you need to specify %2B instead. + sign in the query string is URL-decoded to a space. %2B in the query string is URL-decoded to a + sign.

What is %2f in a URL?

URL encoding converts characters into a format that can be transmitted over the Internet. - w3Schools. So, "/" is actually a seperator, but "%2f" becomes an ordinary character that simply represents "/" character in element of your url. Follow this answer to receive notifications.


2 Answers

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"] = "[email protected]"; values["su"] = "some subject"; values["body"] = "Hi there+Hello there";  uriBuilder.Query = values.ToString();  Console.WriteLine(uriBuilder.ToString()); 

The result

https://mail.google.com:443/mail?view=cm&tf=0&to=someemail%40somedomain.com&su=some+subject&body=Hi+there%2bHello+there

like image 199
Darin Dimitrov Avatar answered Sep 21 '22 15:09

Darin Dimitrov


If you want a plus + symbol in the body you have to encode it as 2B.

For example: Try this

like image 39
Black Frog Avatar answered Sep 23 '22 15:09

Black Frog