Press "Enter" to skip to content

Expect: 100-continue

When using curl to do a POST, if the data to POST is larger than 1024 bytes, curl won't directly issue the POST request. Instead it splits it into two steps:

1. send a request containing an Expect:100-continue, asking the Server whether it's willing to accept the data
2. only after receiving the Server's 100-continue response, does it POST the data to the Server

This is libcurl's behavior.
The relevant RFC description: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3
So this creates a problem: not every Server will respond to 100-continue correctly. For example, lighttpd returns 417 "Expectation Failed", which causes the logic to go wrong,,
The fix is also pretty easy:

// Disable Expect: header (lighttpd does not support it)
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.