You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HTML表单提交未指定UTF-8编码致日文参数解析异常求助

解决表单提交日文乱码:添加charset到Content-Type请求头

你的问题根源是表单默认提交application/x-www-form-urlencoded时,浏览器不会自动在请求头的Content-Type字段里附加charset=utf-8,导致服务器可能用非UTF-8编码解析日文参数,进而出现乱码。

直接有效的解决办法是给<form>标签添加accept-charset="UTF-8"属性,浏览器会自动在提交请求时把Content-Type设为application/x-www-form-urlencoded; charset=UTF-8,服务器就能正确解析日文参数。

修改后的HTML代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Form with UTF-8</title>
</head>
<body>

<form action="/reporting" method="post" accept-charset="UTF-8">
    <!-- Form fields go here -->
    <label for="name">Name:</label>
    <input type="text" id="name" name="name">

    <label for="email">Email:</label>
    <input type="email" id="email" name="email">

    <input type="submit" value="Submit">
</form>

</body>
</html>

补充说明

  • 这个属性是HTML标准定义的,所有现代浏览器都支持,不需要额外JS处理。
  • 如果无法修改前端,也可以在服务器端强制将application/x-www-form-urlencoded类型的请求按UTF-8解析,但前端添加属性是更通用、更直接的方案。

内容的提问来源于stack exchange,提问作者jaxb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:32:35