[英]Correct way to pass base64 info in URL as query string?
I am sending some parameters in query string by converting them in base64
using method btoa()
.我通过使用方法
btoa()
在base64
转换它们来发送查询字符串中的一些参数。 I just want to know, do I still need to wrap the result into the encodeURI
method to pass on the correct information to the server in URL.我只是想知道,我是否还需要将结果包装到
encodeURI
方法中才能将正确的信息以 URL 的形式传递给服务器。
For example:例如:
http://example.com/{name}
- For this, which one is correct from below? http://example.com/{name}
-为此,下面哪个是正确的?"http://example.com/" + btoa("some-name")
"http://example.com/" + encodeURI(btoa("some-name"))
You only need to transform your string to Base 64. See this SO answer for C#:您只需要将字符串转换为 Base 64。请参阅 C# 的这个 SO 答案:
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
You can also read the reason why we use Base 64 .您还可以阅读我们使用 Base 64 的原因。
No need to use a method such as encodeURI
after, it would be useless because all the characters for Base 64 (AZ, az, 0-9, =, +) are not escaped :之后不需要使用诸如
encodeURI
的方法,因为 Base 64 (AZ, az, 0-9, =, +) 的所有字符都没有转义:
encodeURI escapes all characters except:
encodeURI 转义所有字符,除了:
AZ az 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
By the way, encodeURI
and btoa
are about JavaScript, not asp.net as you mention in tags.顺便说一下,
encodeURI
和btoa
是关于 JavaScript 的,而不是你在标签中提到的 asp.net。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.