javascriptasp.netquery-stringbase64encodeuricomponent

url-Encode vs Base64 encoding ( usages)?


I was wondering...

(except the issue with the base64's plus'+' sign in query string - which is translated to 'space' and can be solved by %2b) :---> which is the preferred way to transfer data in query string?

Both functions can be used through the JS commands:

so im asking myself(and you) :

when should I use what ? ( ive always used encodeUriCompoonent - by instinct).

the problem that the definitions are different - but the implementations can be similar...

edit

I think ive found the reason for asking.... ( and why nobody asked it before)

enter image description here


Solution

  • base64 is used to transfer binary data. (not supported in IE, cant encode spacial chars.)

    encodeURIComponent only encodes special characters.

    An interesting thing is that you can't apply base64 to unicode strings without encodeURIComponent: https://developer.mozilla.org/en/DOM/window.btoa