Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpUtility.UrlDecode turns %2b into space, but I need it to be '+'

Tags:

html

http

I'm using HttpUtility.UrlEncode to turn parameter value which concluds '+' to safe string deliverd among pages, so it turns '+' into %2b, but when I use Decode method it give me back a space. Why?

like image 550
Steven Zack Avatar asked Jul 19 '11 20:07

Steven Zack


People also ask

What does HttpUtility Urldecode do?

HttpServerUtility. UrlEncode Method (System. Web) Encodes a string for reliable HTTP transmission from the Web server to a client through the URL.

How do you encode a space in a URL?

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

What is Urldecode?

URLDECODE is a string manipulation function that manipulates CHARACTER string data.

What is UrlEncode and Urldecode in PHP?

This is a type of encoding-decoding approach where the built-in PHP functions urlencode() and urldecode()are implemented to encode and decode the URL, respectively. This encoding will replace almost all the special characters other than (_), (-), and (.) in the given URL.


1 Answers

Decoding %2b would give you back a +, but decoding a + would give you back a space.

So, most likely your string is decoded twice. If you are reading it from the Request.Querystring collection, then it's already decoded, so you shouldn't decode it again.

like image 143
Guffa Avatar answered Oct 05 '22 23:10

Guffa