url-Encode vs Base64编码(用法)?

url-Encode vs Base64编码(用法)?

问题描述:

我想知道......

I was wondering...

(除了base64的问题加上查询字符串中的'+'符号 - 这被转换为'space'并且可以通过%2b)来解决::--->这是在查询字符串中传输数据的首选方法吗?

(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?

这两个函数都可以通过JS命令:

Both functions can be used through the JS commands:


  • btoa

  • encodeUriComponent

  • btoa
  • encodeUriComponent

所以我问自己(和你):

so im asking myself(and you) :

何时我应该使用什么? (我总是使用 encodeUriCompoonent - 本能)。

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

定义不同的问题 - 但实现可以相似......

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

我想我已经找到了询问的原因....(和以前没有人问过这个问题)

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

base64 用于传输二进制数据。 (在IE中不支持,无法编码空格字符。)

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

encodeURIComponent 仅对特殊字符进行编码。

encodeURIComponent only encodes special characters.

有趣的是,如果没有encodeURIComponent,你不能将base64应用于unicode字符串:
https://developer.mozilla.org/en/DOM/window.btoa

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