最近在使用python 的 pcurl 发送 post 请求到服务端的时候【服务端使用的服务是Lighttpd】,发现只要 post 请求的数据超过 1024 以后,就会返回以下错误:html
* Hostname was NOT found in DNS cache * Trying 10.8.2.54... * Connected to 10.8.2.54 (10.8.2.54) port 9997 (#11) > POST /rest/cm/changeconfig HTTP/1.1 User-Agent: PycURL/7.43.0 libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3 Host: 10.8.2.54:9997 Accept: application/json Authorization: Basic YXJyYXk6YWRtaW4= Content-Length: 1025 Content-Type: application/x-www-form-urlencoded Expect: 100-continue < HTTP/1.1 417 Expectation Failed < Content-Type: text/html < Content-Length: 363 < Connection: close < Date: Wed, 26 Apr 2017 17:34:58 GMT * Server lighttpd/1.4.34 is not blacklisted < Server: lighttpd/1.4.34 < * Closing connection 11
百思不得其解,post 的数据为 1024 的时候,能够正常使用,因而乎在客户端和服务端分别抓包看了一眼。10.8.2.68:客户端 10.8.2.54:服务端python
从数据包能够看出,首先客户端和服务端三次握手成功以后,因为post数据超过了1024,超过了链路最大传输单元,须要分片。此时客户端发送一个发送一个请求, 包含一个Expect:100-continue, 询问Server使用愿意接受数据,客户端接收到Server返回的100-continue应答之后, 才把数据POST给Server。因而,这样就有了一个问题, 并非全部的Server都会正确应答100-continue, 好比lighttpd, 就会返回417 “Expectation Failed”, 则会形成逻辑出错。json
查询一下说是lighttpd v1.4.x不支持“Expect: 100-continue”HTTP头,解决的方法以下:app
一:使用 Lighttpd 1.50curl
二:lighttpd 1.4.21或以上版本(即最新的realease版本),只要在lighttpd配置文件中加入server.reject-expect-100-with-417="disable"便可post