How to encode the plus (+) symbol in URL
url encode plus
php url encode
c# url encode
url encoding characters
how to pass special characters in url
The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) sign in the email body with blank space. It looks like it only happens with the + sign. Any suggestions on how to remedy this? ( I am working the ASP.NET web page)
https://firstname.lastname@example.org&su=some subject&body=Hi there+Hello there
(In the body email, "Hi there+Hello there" will show up as "Hi there Hello there")
+ character has a special meaning in a url => it means whitespace. If you want to use the
+ sign you need to URL encode it:
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@example.com"; values["su"] = "some subject"; values["body"] = "Hi there+Hello there"; uriBuilder.Query = values.ToString(); Console.WriteLine(uriBuilder.ToString());
How to encode the plus (+) symbol in URL, For example, spaces in a string are either encoded with %20 or replaced with the plus sign ( + ). If you use a pipe character ( | ) as a separator, be sure to encode How to encode the plus (+) symbol in URL. The URL link below will open a new Google mail window. The problem I have is that Google replaces all the plus (+) sign in the email body with blank space. It looks like it only happens with the + sign.
Is you want a plus (+) symbol in the body you have to encode it as 2B.
For example: Try this
How to Pass a Plus Sign to a URL?, URL Encoding Issue for Plus Symbol (%2B) #210. Closed. imaurer opened this issue on Jun 16, 2016 · 11 comments. Closed Your request is getting rejected by request filtering module. See this blog on interaction between urlrewrite and request filtering. See this blog which explains request filtering behavior of rejected URLs with '+' and how to fix it.
It's safer to always percent-encode all characters except those defined as "unreserved" in RFC-3986.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
So, percent-encode the plus character and other special characters.
The problem that you are having with pluses is because, according to RFC-1866 (HTML 2.0 specification), paragraph 8.2.1. subparagraph 1., "The form field names and values are escaped: space characters are replaced by `+', and then reserved characters are escaped"). This way of encoding form data is also given in later HTML specifications, look for relevant paragraphs about application/x-www-form-urlencoded.
+ (Plus) in URL parameter converted to %2B · Issue #3042 · angular , Fragment identifiers and relative URIs are not involved in the basic URL In either case, the encoding may use those characters allowed by the BNF syntax, Within the query string, the plus sign is reserved as shorthand notation for a space. URL Encoding. URLs can only be sent over the Internet using the ASCII character-set. If a URL contains characters outside the ASCII set, the URL has to be converted. URL encoding converts non-ASCII characters into a format that can be transmitted over the Internet.
Percent-encoding, The <space> character needs to be encoded because it is not a valid URL character. Also, some characters, such as "~" might not transport URL encode your data in a hassle-free way, or decode it into human-readable format. URL encoding, also known as percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI) under certain circumstances.
Universal Resource Identifiers: Recommendations, urldecode — Decodes URL-encoded string Plus symbols ('+') are decoded to a space character. foo.php?myvar=%C2%BA (The "right" url encoding) Encoding space characters to plus sign (+) using quote_plus() function The quote() function encodes space characters to %20 . If you want to encode space characters to plus sign ( + ), then you can use another function named quote_plus provided by urllib.parse package.
- The RFC clearly says that the + sign can be used unencoded, and also if it had to be encoded, there is no reason to turn it into a "space" character. Maybe you can point us to a proper document of a standard mentioning what is that of translating a + symbol into a space symbol and vice-versa.
- Yeah what are you talking about? I've never seen an RFC or anything that says + means spaces....
- Warning: If you use the
UriBuilderyou will get a bad result.
uriBuilder.Uri.ToString()in your example would return
uriBuilder.Uri.AbsoluteUriseems to work correctly and stackoverflow.com/a/15120429/1931573 suggests this is fixed in .NET 4.5. As far as RFC goes, the HTML 4 spec says the URL querystring is of type
application/x-www-form-urlencodedwhich itself defines (+) as meaning space. So it's not an RFC but is part of the HTML standard.
- @freedrull but it really works this way - that shows the number of upvotes
- Note that IIS considers this "double encoding" and will often block a url loaded this way with this error: HTTP Error 404.11 - Not Found The request filtering module is configured to deny a request that contains a double escape sequence.