c# - .NET UrlEncode not working? -


according http://www.w3schools.com/tags/ref_urlencode.asp when requests submitted url encoded, example space gets transformed %20. far good.

i have problem !. submitting in form converts %21 should. httputility.urlencode (or webutility partner) or uri.escapedatastring return ! expected behaviour? how should encode input c# converts proper values?

an exclamation mark considered url-safe ascii character , therefore not percentage encoded.

from msdn

the urlencode method url-encodes character not in set of ascii characters considered url-safe. spaces encoded ascii "+" character. url-safe ascii characters include asci characters (a z , z), numerals (0 9), , punctuation marks. following table lists punctuation marks considered url-safe ascii characters.

the table contains - _ . ! * ( )

update

according this answer, uri.escapedatastring should encode ! when targetting .net 4.5 projects i'm unable test on current machine. escapedatastring on previous .net frameworks not percentage encode characters above. may need use string.replace , replace characters above escaped uri.


Comments

Popular posts from this blog

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -