# HTTP 417 Expectation Failed

**HTTP 417 Expectation Failed** 是一种客户端错误响应状态码，表示请求的 `Expect` 头字段中所给出的期望无法被至少一个入站服务器满足。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> 它属于 4xx 类别，该类别的含义是请求中包含服务器无法完成的内容；该状态码由 RFC 9110 第 15.5.18 节注册于 IANA。<sup>[2](https://www.iana.org/assignments/http-status-codes)</sup>

| 关键事实 | 详情 |
|---|---|
| 含义 | 请求的 `Expect` 头中的期望无法被至少一个入站服务器满足<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup> |
| 注册表 | IANA HTTP 状态码注册表，RFC 9110 第 15.5.18 节<sup>[2](https://www.iana.org/assignments/http-status-codes)</sup> |
| 首次定义 | RFC 2616（HTTP/1.1，1999 年 6 月），第 10.4.18 节<sup>[3](https://www.rfc-editor.org/info/rfc2616/)</sup> |
| 已定义的期望值 | HTTP 规范唯一定义的值是 `100-continue`<sup>[4](https://.dev/expect)</sup> |
| 客户端恢复 | 去掉 `Expect` 头重发请求，不等待 `100` 响应直接发送正文<sup>[5](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/417)</sup> |
| 典型触发场景 | curl 等命令行客户端在正文已知或怀疑超过一兆字节时自动添加 `Expect: 100-continue`<sup>[4](https://.dev/expect)</sup> |

## Expect 头的用途

`Expect` 请求头让客户端在发送可能很大的正文之前，先检查服务器是否会接受该请求。客户端发送请求头，其中包含 `Expect: 100-continue` 和 `Content-Length`，然后等待。如果服务器返回 `100 Continue`，客户端就发送正文；如果请求无论如何都会失败——例如因为认证错误、大小限制或不支持的媒体类型——服务器会在任何正文数据经过网络之前返回 `401` 或 `413` 之类的错误状态。<sup>[4](https://.dev/expect)</sup>

无法满足期望的服务器会以 `417` 响应，或者如果请求还有其他问题，则以另一个 4xx 状态响应。根据 RFC 2616，收到不支持的期望扩展的服务器必须返回 417。<sup>[6](https://www.rfc-editor.org/rfc/rfc2616.html)</sup> 对于不带引号的令牌（包括 `100-continue` 令牌本身），期望值的比较不区分大小写。<sup>[6](https://www.rfc-editor.org/rfc/rfc2616.html)</sup>

## 各版规范中的历史

该状态码首次出现在 RFC 2616——1999 年 6 月发布的 HTTP/1.1 规范——的第 10.4.18 节。<sup>[3](https://www.rfc-editor.org/info/rfc2616/)</sup> RFC 7231（2014 年 6 月）将其沿袭为第 6.5.14 节。<sup>[7](https://www.rfc-editor.org/rfc/rfc7231.html)</sup> 现行定义见于 RFC 9110（2022 年 6 月），其中称期望“无法被至少一个入站服务器满足”，这一措辞承认响应链中的任何一台服务器都可能是失败的那一台。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

代理规则在前后规范之间发生了变化。RFC 2616 将 Expect 机制视为逐跳的（在每个中间服务器处处理，而非端到端）：收到带有无法满足的期望的请求的 HTTP/1.1 代理必须自行返回 417，尽管该头字段是端到端的、必须转发。<sup>[6](https://www.rfc-editor.org/rfc/rfc2616.html)</sup> 现行规范删除了这一指示；中间服务器将 `Expect` 头转发给源服务器，无法满足期望的代理仍可生成 417，但不再被要求这样做。<sup>[4](https://.dev/expect)</sup><sup> • </sup><sup>[8](https://hivebook.wiki/wiki/http-100-continue-expect-headers-client-thresholds-and-proxy-traps)</sup>

## 客户端恢复

417 响应并不一定意味着请求本身无效。RFC 7231 指出，收到针对 `100-continue` 期望的 417 的客户端应去掉该期望重发请求，因为该响应可能仅仅表明响应链不支持期望——例如请求经过了一台 HTTP/1.0 服务器。<sup>[9](https://www.ietf.org/ietf-ftp/rfc/rfc7231.txt.pdf)</sup> MDN 给出了同样的实用建议：去掉 `Expect` 头重发请求，将文件包含在请求正文中发送，而不等待 `100` 响应。<sup>[5](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/417)</sup>

## 实际行为

对 `100-continue` 的支持程度参差不齐。有些服务器和负载均衡器完全忽略该期望，让客户端在短暂超时后发送正文，这就使该特性变成了每次请求固定的延迟，而非节省。<sup>[4](https://.dev/expect)</sup> 反向代理也可能自行应答临时的 `100`，于是源服务器根本看不到该期望。<sup>[8](https://hivebook.wiki/wiki/http-100-continue-expect-headers-client-thresholds-and-proxy-traps)</sup>

有些平台会直接拒绝意外的值。如果 `Expect` 头包含 `100 Continue` 以外的任何值（不区分大小写），Heroku 的路由器会自动返回 `417 Expectation Failed` 并关闭与应用的连接。<sup>[10](https://devcenter.heroku.com/articles/http-routing)</sup> 相比之下，[Cloudflare](https://www.edgepedia.org/zh/cloudflare) 在遇到不支持或未满足的 `Expect` 头时，通常会将源服务器返回的 417 转发出去。<sup>[11](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-417/)</sup>

客户端行为也各不相同。常见浏览器都不发送 `Expect` 头，但一些命令行工具默认会发送。<sup>[12](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect?retiredLocale=he)</sup> curl 在正文已知或怀疑超过一兆字节时自动添加 `Expect: 100-continue`，也可以禁用，例如使用 `curl -H "Expect:"`。<sup>[4](https://.dev/expect)</sup><sup> • </sup><sup>[13](https://www.httpstatus.com/417/)</sup> HTTP/2 和 HTTP/3 保持相同的语义，但很少依赖临时的 `100` 响应。<sup>[4](https://.dev/expect)</sup>

## 相关状态码

417 与服务器在评估期望时可能改为返回的其他状态不同。如果请求会因实质性原因失败，服务器会以该原因对应的代码响应，例如上传过大时返回 `413 Content Too Large`，缺少凭据时返回 `401 Unauthorized`，并且不会传输任何正文。<sup>[4](https://.dev/expect)</sup> 417 本身报告的是期望机制的失败，而非底层请求的失败。<sup>[1](https://www.rfc-editor.org/rfc/rfc9110.html)</sup>

## References

1. [RFC 9110: HTTP Semantics, RFC Editor](https://www.rfc-editor.org/rfc/rfc9110.html)
2. [Hypertext Transfer Protocol (HTTP) Status Code Registry, IANA](https://www.iana.org/assignments/http-status-codes)
3. [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1, RFC Editor](https://www.rfc-editor.org/info/rfc2616/)
4. [Expect - Expert Guide to HTTP headers, http.dev](https://.dev/expect)
5. [417 Expectation Failed - HTTP, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/417)
6. [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1, RFC Editor](https://www.rfc-editor.org/rfc/rfc2616.html)
7. [RFC 7231: HTTP/1.1 Semantics and Content, RFC Editor](https://www.rfc-editor.org/rfc/rfc7231.html)
8. [HTTP 100-continue - Expect Headers, Client Thresholds, and Proxy Traps, Hivebook](https://hivebook.wiki/wiki/http-100-continue-expect-headers-client-thresholds-and-proxy-traps)
9. [RFC 7231 (PDF), IETF](https://www.ietf.org/ietf-ftp/rfc/rfc7231.txt.pdf)
10. [HTTP Routing, Heroku Dev Center](https://devcenter.heroku.com/articles/http-routing)
11. [Error 417, Cloudflare Support docs](https://developers.cloudflare.com/support/troubleshooting/http-status-codes/4xx-client-error/error-417/)
12. [Expect header - HTTP, MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect?retiredLocale=he)
13. [417 Expectation Failed - HTTP status code explained, HttpStatus.com](https://www.httpstatus.com/417/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › HTTP and web communication protocols › HTTP status codes

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/http-417-expectation-failed

English original: https://www.edgepedia.org/http-417-expectation-failed
