HttpClient4.1を使ってみたので、
サンプルを載っけておきます。
HTTP Status CodeとContent-Typeを
表示するサンプルです。
public class HttpClientSample {
public static void main(String[] args) {
HttpClient client = new DefaultHttpClient();
HttpGet getMethod = new HttpGet(URLを指定);
try {
HttpResponse response = client.execute(getMethod);
System.out.println("HTTP Status Code: " + response.getStatusLine().getStatusCode());
String contentType = response.getEntity().getContentType().getValue();
System.out.println("Content-Type: " + contentType);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
HttpClient 3.0と異なって、HttpClientがインターフェースに
なっているので、new するのはDefaultHttpClientになります。
あと、実行メソッド名がexecuteMethod()ではなく、
execute()になっていたり、ステータスコードの取得方法が
変わっていたりと、異なる部分がいろいろあります。
なお、使用するときは依存するライブラリを入れるのを忘れずに。