do Http Get Request and return the status code
import java.net.HttpURLConnection;
import java.net.URL;
import android.util.Log;
class Main {
public static int doHttpGetRequest(String url) {
try {
HttpURLConnection conn = (HttpURLConnection) (new URL(url))
.openConnection();
conn.setUseCaches(false);
conn.connect();
int status = conn.getResponseCode();
conn.disconnect();
return status;
} catch (Exception e) {
Log.e("doHttpGetRequest", e.toString());
}
return 0;
}
}
Related examples in the same category