Skip to content

Instantly share code, notes, and snippets.

@tshrkmd
Created February 17, 2013 06:47
Show Gist options
  • Save tshrkmd/4970484 to your computer and use it in GitHub Desktop.
Save tshrkmd/4970484 to your computer and use it in GitHub Desktop.
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