ラベル HttpComponents の投稿を表示しています。 すべての投稿を表示
ラベル HttpComponents の投稿を表示しています。 すべての投稿を表示

2011年5月2日月曜日

HttpComponentsのプログラミング…始めたばかり

ほとんど自分メモ。
Apache Http Componentsでシクったので、自分メモ。

Good!な例

public String getResource() throws URISyntaxException,
        ClientProtocolException, IOException {
    URI uri = URIUtils.createURI("http", HOST_NAME,
                    PORT_NUMBER, PATH_NAME, queryString,
                    null);
    HttpGet hGet = new HttpGet(uri);
    HttpClient client = new DefaultHttpClient();
    return client.execute(hGet, new BasicResponseHandler());
  }


BAD!な例

public String getResource() throws URISyntaxException,
        ClientProtocolException, IOException {
    URI uri = URIUtils.createURI("http", HOST_NAME,
                    PORT_NUMBER, PATH_NAME, queryString,
                    null);
    HttpGet hGet = new HttpGet(uri);
    HttpClient client = new DefaultHttpClient();
    HttpEntity entity = client.execute(hGet);
    InputStream input = entity.getContent();

    //.....
  }