PHP/cURL: disable 100-continue expectation

December 29, 2008 / Filed under: Apache, 100-continue, cURL, Twitter, API

Twitter recently changed their API to disallow requests with the 100-continue expectation included. This had an immediate effect on various third-party services using the API to post updates. View full Google Group thread here.

The response coming back from the server was status 417: Expectation Failed.

This has to do with the 100-continue header, which Apache displays as such:

HTTP/1.1 100 Continue

This 100-continue status is "expected" by default when using cURL:

Expect: 100-continue

To turn it off this expectation in your PHP code, use this command:

curl_setopt( $curl_handle, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

I discovered this quick tip at this helpful site.

You can read more about the 100 (Continue) status at w3.org.

Comments/Mentions

# Pain at 10/11/2009 9:27 pm cst

Beautiful, thank you.

# Amir at 8/1/2010 9:02 am cst

thank you very very much, this helped me greatly