{
  "id": "nextjs/server-action-body-parsed-json-error",
  "signature": "Error: Server Actions require the request body to be parsed as FormData or JSON. Received unexpected content type.",
  "signature_zh": "错误：服务器操作需要将请求体解析为 FormData 或 JSON。收到意外的内容类型。",
  "regex": "Server Actions require the request body to be parsed as FormData or JSON",
  "domain": "nextjs",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "Server Actions in Next.js expect the client to send requests with Content-Type application/x-www-form-urlencoded or multipart/form-data (for form submissions) or application/json (for programmatic calls). An unsupported content type (e.g., text/plain) causes parsing failure.",
  "root_cause_type": "generic",
  "root_cause_zh": "Next.js 中的服务器操作期望客户端发送带有 Content-Type application/x-www-form-urlencoded 或 multipart/form-data（用于表单提交）或 application/json（用于编程调用）的请求。不支持的内容类型（例如 text/plain）会导致解析失败。",
  "versions": [
    {
      "version": "14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "14.2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "15.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "15.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding 'Content-Type: multipart/form-data' header manually in JavaScript fetch calls without properly encoding the body",
      "why_fails": "The server still receives the body as a string, not as multipart parts. The content type must match the actual encoding.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting 'bodyParser: false' in API route configuration for Server Actions",
      "why_fails": "Server Actions do not use the API route body parser; they have their own parsing logic. Disabling it has no effect.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using JSON.stringify on FormData before sending",
      "why_fails": "FormData is not a plain object; JSON.stringify will return an empty object. The server expects actual FormData entries.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure client-side form submissions use the standard HTML form element or the 'useFormState' hook, which automatically sends the correct content type. For programmatic calls, use 'new FormData(formElement)' or pass a plain object and set Content-Type: application/json.",
      "success_rate": 0.9,
      "how": "Ensure client-side form submissions use the standard HTML form element or the 'useFormState' hook, which automatically sends the correct content type. For programmatic calls, use 'new FormData(formElement)' or pass a plain object and set Content-Type: application/json.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using fetch directly, construct the body as FormData: const formData = new FormData(); formData.append('key', value); await fetch('/action', { method: 'POST', body: formData });",
      "success_rate": 0.85,
      "how": "If using fetch directly, construct the body as FormData: const formData = new FormData(); formData.append('key', value); await fetch('/action', { method: 'POST', body: formData });",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure client-side form submissions use the standard HTML form element or the 'useFormState' hook, which automatically sends the correct content type. For programmatic calls, use 'new FormData(formElement)' or pass a plain object and set Content-Type: application/json.",
    "If using fetch directly, construct the body as FormData: const formData = new FormData(); formData.append('key', value); await fetch('/action', { method: 'POST', body: formData });"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#behavior",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-05-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}