Skip to content

Instantly share code, notes, and snippets.

@nestoru
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nestoru/10281854 to your computer and use it in GitHub Desktop.
Save nestoru/10281854 to your computer and use it in GitHub Desktop.
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* @author Nestor Urquiza
* @date 20140409
*
* /
public class GetHttpStatusCode {
/**
* Returns the status code for a URL
* It can be used to test if a certificate for a remote site has been authorized in the default keystore
*
* /
public static void main(String[] args) throws java.io.IOException {
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(args[0]);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
int statusCode = httpResponse.getStatusLine().getStatusCode();
System.out.println(statusCode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment