url-Encode vs Base64编码(用法)? [英] url-Encode vs Base64 encoding ( usages)?

查看:539
本文介绍了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

这篇关于url-Encode vs Base64编码(用法)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆