在 Linux 下,可以使用命令行工具 curl 或 perl 来进行 URL 编码
curl 进行 URL 编码:echo -n "需要编码的字符串" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | cut -c 3- 将 “需要编码的字符串” 替换为实际需要编码的内容。
perl 进行 URL 编码:首先确保已经安装了 Perl,然后运行以下命令:
echo -n "需要编码的字符串" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' 将 “需要编码的字符串” 替换为实际需要编码的内容。
这两种方法都会将输入的字符串进行 URL 编码,并将结果输出到终端。