使用EncodeURI后再次对EncodedURIComponent进行编码

问题描述

我正在尝试对URL进行结尾编码。 URL中的参数值之一包含,因此我们使用encodeURIComponent对其进行编码。之后,我们还需要对整个URL进行编码,然后对编码后的值进行重新编码。在这种情况下我们该怎么办?

Value to be encoded,encodeURICOmponent('A & B')
encodedvalue = A%20%26%20B
Query param = {"filter":{"ab":{"$like":"%A%20%26%20B%"}}}
encodeURI(param)

finalURL = %7B%22filter%22%3A%7B%22e2%22%3A%7B%22%24like%22%3A%22%25A%2520%2526%2520B%25%22%7D%7D%7D

解决方法

仅应用一次编码。

const value = 'A & B';
const param = JSON.stringify({"filter":{"ab":{"$like":value}}});
const url = encodeURI(param);
console.log(url);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...