Javascript 单词之间的间距会破坏URL吗? exports.exec=async(客户端、消息、参数)=>{ //激发错误消息,说明命令未正确运行。 如果(参数长度
嘿,伙计们,上面是命令,当尝试添加几个单词时,它可以工作。“hello world它只捕捉hello,在放置空格后会中断。我不完全确定如何允许空格 感谢您的帮助 范例-Javascript 单词之间的间距会破坏URL吗? exports.exec=async(客户端、消息、参数)=>{ //激发错误消息,说明命令未正确运行。 如果(参数长度,javascript,discord,discord.js,Javascript,Discord,Discord.js,嘿,伙计们,上面是命令,当尝试添加几个单词时,它可以工作。“hello world它只捕捉hello,在放置空格后会中断。我不完全确定如何允许空格 感谢您的帮助 范例- 您可以使用表示空格的%20。URL中的特殊字符使用称为百分比编码的格式进行编码 空格由%20表示 例如https://example.com/hello%20world/ 进一步阅读: 我不知道您使用的编程语言,但编码URL可能会有所帮助。下面是Python中的一个示例: def encode_url(url): 编码=“
您可以使用表示空格的
%20
。URL中的特殊字符使用称为百分比编码的格式进行编码
空格由%20
表示
例如https://example.com/hello%20world/
进一步阅读:
def encode_url(url):
编码=“”
对于url中的特殊字符:
编码+='%'+hex(ord(特殊字符)).lstrip('0x'))
返回编码
所以encode\u url('Hello World!')
将返回'%48%65%6c%6c%6f%20%57%6f%72%6c%64%21'
,这在url中是可以接受的。
console.log(encodeURIComponent('hello world!');
因为空格是不安全的字符
用于url编码
URL编码将URL中的保留、不安全和非ASCII字符转换为所有web浏览器和服务器普遍接受和理解的格式
exports.exec = async (client, message, args) => {
// Fires Error message that the command wasn't ran correctly.
if (args.length < 1) {
return message.channel.send({
embed: {
color: 0,
description: `${message.author} Please input something to be generated into the QR code.`
}
});
}
// Fires Error message that the command wasn't ran correctly.
var text = args.join(' ');
var qr_generator = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${text}`;
message.channel.send(qr_generator);
};
escape
已从Web标准中删除。对,在data=
之后的所有内容上使用,应该是完美的。
var qr_generator = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${encodeURIComponent(text)}`;