PHP/cURL: disable 100-continue expectation

Posted by Matt Thommes on December 29, 2008 | Post type: Gain

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

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

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:') );

Here we're basically setting the value to nothing.

I discovered this quick tip at this helpful site.

  1. http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3
  2. http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18

About the author(s)

Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Comments

Note: Comments may be viewed by authors, but if you have a more specific question you'd like to ask them, please email matt.thommes@paininthetech.com.

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

Beautiful, thank you.

Quick Link to this comment: http://TTIP.me/c5352