Created
February 17, 2013 06:47
-
-
Save tshrkmd/4970484 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment