跳到主要内容
uencoder

Form Encoding

表单编码(application/x-www-form-urlencoded)是 HTML 表单提交时键值对的编码方式,空格编码为 + 而非 %20。

用途

在 Web 早期表单提交场景中提供比 RFC 3986 更宽松的编码,兼容历史实现。

机制

键与值分别百分号编码,但空格用 + 替代 %20;键值用 = 连接,对用 & 分隔。非 ASCII 字符按页面 charset(通常 UTF-8)转为字节再百分号编码。

用例

  • HTML 表单 GET/POST 提交
  • OAuth 1.0 签名参数编码
  • application/x-www-form-urlencoded 表单编码请求体
  • fetch URLSearchParams 请求体

示例

  • 输入
    a=hello world&b=a+b
    输出
    a=hello+world&b=a%2Bb

    Space becomes +, and + becomes %2B

常见错误

Encoding a space as %20 instead of +, causing server-side parsing differences
Use URLSearchParams for form scenarios and encodeURIComponent for URL components

相关词条

相关工具

参考链接