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(); //..... }
0 件のコメント:
コメントを投稿