30 June 2009

Switching off Expect: 100-Continue header with Apache HttpClient

Apache HTTP client version 4.0 (at least, the version bundled with the Android SDK) adds the header "Expect: 100-Continue" by default, which confuses many web servers. The following snippet switches this header off:

HttpClient client = new DefaultHttpClient();
client.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);

I was seeing an error response like the following before I switched this header off:

HTTP/1.1 417 Expectation Failed.
Date: Tue, 30 Jun 2009 10:03:59 GMT.
Server: hi.
Vary: Accept-Encoding.
Content-Length: 364.
Connection: close.
Content-Type: text/html; charset=iso-8859-1.

417 Expectation Failed
Expectation Failed
The expectation given in the Expect request-header field could not be met by this server.
The client sent Expect: 100-Continue but we only allow the 100-continue expectation.

Copying package selections with debian/ubuntu

This is documented in lots of places but it seems to always take me a while to find it. Here is how to install the set of packages from one machine to another.
  1. On the source machine: sudo dpkg --get-selections > output_file
  2. Transfer the output file to the target machine
  3. On the target machine: sudo dpkg --set-selections <>
  4. On the target machine: sudo apt-get -u dselect-upgrade