# http：无效的Content-Length

- **ID:** `go/http-multiple-content-length`
- **领域:** go
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

HTTP请求或响应包含多个值不同的Content-Length头，导致Go的net/http拒绝该请求。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.22 | active | — | — |

## 解决方案

1. **** (75% 成功率)
   ```
   if req.Header.Get("Content-Length") != "" {
    // Validate and use a single value
} else {
    // Handle missing Content-Length
}
   ```
2. **** (80% 成功率)
   ```
   Use a custom RoundTripper to sanitize headers before sending.
   ```

## 无效尝试

- **** — The body may be corrupted or incomplete, leading to data integrity issues. (80% 失败率)
- **** — Does not resolve the underlying inconsistency and may cause parsing errors. (60% 失败率)
