跳转到内容
POST AI agent ready /v1/url/encode

URL 编码 API - 免费百分比编码

将字符串转换为百分比编码格式 (RFC 3986)。 空格变为 %20,特殊字符变为其对应的十六进制字符。 可安全用于 URL 查询参数和路径段。

Parameters

stringrequired

The string to URL-encode.

Code examples

curl -X POST https://api.botoi.com/v1/url/encode \
  -H "Content-Type: application/json" \
  -d '{"text":"hello world & goodbye=test"}'

When to use this API

构建安全的查询字符串

在将用户提供的搜索词附加到 URL 之前对其进行编码,以便 &、= 和 # 等特殊字符不会破坏 URL 结构。

编码重定向 URI

在将回调 URL 作为 OAuth redirect_uri 参数传递之前对其进行百分比编码,以避免双重编码问题。

Frequently asked questions

这会将空格编码为 + 或 %20 吗?
此 API 使用 RFC 3986 的 %20。+ 编码特定于 application/x-www-form-urlencoded,此处不使用。
哪些字符没有被编码?
未保留的字符(A-Z、a-z、0-9、-、_、.、~)按照 RFC 3986 保留原样。其他所有字符均按百分比编码。
我可以对整个 URL 进行编码吗?
可以,但对斜杠和冒号进行编码会破坏 URL 结构。 仅对查询参数值或路径段进行编码,而不对完整 URL 进行编码。
是否处理双编码?
不会。如果您的输入已包含百分比编码字符(例如 %20),它们将再次编码为 %2520。 如果需要,请先解码。

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.