# 错误：服务器操作要求将请求体解析为 FormData 或 JSON。收到意外的内容类型：application/x-www-form-urlencoded

- **ID:** `nextjs/server-action-formdata-encoding`
- **领域:** nextjs
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

服务器操作以非标准内容类型（例如 application/x-www-form-urlencoded）被调用，而非 multipart/form-data 或 application/json。这通常发生在通过 fetch 手动提交表单而未设置正确标头时。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 14.2.0 | active | — | — |
| 15.0.0 | active | — | — |
| 14.2.15 | active | — | — |

## 解决方案

1. ```
   Use the native form action attribute with a Server Action function directly, which automatically handles proper encoding.
   ```
2. ```
   If calling from JavaScript, use FormData object and avoid setting Content-Type header (let the browser set it automatically).
   ```

## 无效尝试

- **Adding 'Content-Type: multipart/form-data' manually without FormData** — The content type must match the actual body format. Sending multipart/form-data with a JSON string body still fails because the server expects FormData parsing. (85% 失败率)
- **Setting enctype attribute on the HTML form to 'application/json'** — HTML forms natively only support application/x-www-form-urlencoded, multipart/form-data, and text/plain. application/json is not valid for form submission. (90% 失败率)
- **Using JSON.stringify on FormData before sending** — FormData cannot be serialized with JSON.stringify. You must send the FormData object directly as the body. (95% 失败率)
