最近在使用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