Java Utililty Methods HTTP Response Code

List of utility methods to do HTTP Response Code

  1. HOME
  2. Java
  3. H
  4. HTTP Response Code

Description

The list of methods to do HTTP Response Code are organized into topic(s).

Method

int getResponseCode(String URL)
get Response Code
int connectionTimeoutInMS = 3000;
int socketOperationsTimeoutInMS = 3000;
HttpURLConnection conn = null;
URL testUrl = new URL(URL);
conn = (HttpURLConnection) testUrl.openConnection();
conn.setConnectTimeout(connectionTimeoutInMS);
conn.setReadTimeout(socketOperationsTimeoutInMS);
conn.setRequestMethod("HEAD");
...
int getResponseCode(String urlS)
get Response Code
URL url = new URL(urlS);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
return connection.getResponseCode();
int getResponseCode(String urlString)
get Response Code
try {
 URL u = new URL(urlString);
 HttpURLConnection huc = (HttpURLConnection) u.openConnection();
 huc.setRequestMethod("GET");
 huc.connect();
 return huc.getResponseCode();
} catch (MalformedURLException ex) {
 throw new RuntimeException(ex);
...
int getResponseCode(String urlString)
get Response Code
URL u = new URL(urlString);
HttpURLConnection huc = (HttpURLConnection) u.openConnection();
huc.setRequestMethod("GET");
huc.setRequestProperty("User-Agent",
 "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
huc.connect();
int responseCode = huc.getResponseCode();
huc.disconnect();
...
int getResponseCode(String urlString)
get Response Code
try {
 return getResponseCode(new URL(urlString));
} catch (MalformedURLException e) {
 return 0;
int getResponseCode(URL url)
returns response status code for specified URL
HttpURLConnection.setFollowRedirects(false);
HttpURLConnection huc = (HttpURLConnection) url.openConnection();
return huc.getResponseCode();
int getResponseCode(URLConnection connection)
Returns the response code for the given URL connection (assuming this connection represents a HTTP(S) URL).
try {
 if (connection instanceof HttpURLConnection) {
 return ((HttpURLConnection) connection).getResponseCode();
 return -1;
} catch (IOException exception) {
 return handleIOException(connection);


AltStyle によって変換されたページ (->オリジナル) /