URL中如果出现非ASCII字符时需要进行编码(encode)

本文详细介绍了URL中哪些字符需要进行编码及其编码方式。指出仅特定的ASCII字符集可用于URL,包括字母、数字及部分标点符号。对于超出此范围的字符,如文件名中的特殊符号等,必须使用百分号编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当URL中的字符是什么的时候需要编码(encode)呢? 如下所述:

characters used in URLs must come from a fixed subset of ASCII, specifically:

  • The capital letters A-Z

  • The lowercase letters a-z

  • The digits 0-9

  • The punctuation characters - _ . ! ~ * ' (and ,)

The characters : / & ? @ # ; $ + = and % may also be used, but only for their specified purposes. If these characters occur as part of a filename, they and all other characters should be encoded.

The encoding is very simple. Any characters that are not ASCII numerals, letters, or the punctuation marks specified earlier are converted into bytes and each byte is written as a percent sign followed by two hexadecimal digits. Spaces are a special case because they're so common. Besides being encoded as %20, they can be encoded as a plus sign (+). The plus sign itself is encoded as %2B. The / # = & and ? characters should be encoded when they are used as part of a name, and not as a separator between parts of the URL.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值