Thursday, September 10, 2009

Set the Host header in httpclient

It's not enough to call GetMethod#setHeader("Host", "foo.com") -- httpclient will override it with the actual host from the URL you're getting. Instead, use http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/params/HttpMethodParams.html#setVirtualHost%28java.lang.String%29