Created
February 17, 2013 06:47
Revisions
-
kerukerupappa created this gist
Feb 17, 2013 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; public class GetYahoo { public static void main(String args[]){ System.out.println(doGet("http://www.yahoo.co.jp/")); } //HTTP GET public static String doGet( String url ) { try { HttpGet method = new HttpGet( url ); DefaultHttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute( method ); int status = response.getStatusLine().getStatusCode(); if ( status != HttpStatus.SC_OK ) { return "エラー"; } return EntityUtils.toString( response.getEntity(), "UTF-8" ); } catch ( Exception e ) { return e.getMessage(); } } }