code: private URL getRedirectURL(String location) throws IOException {
          HttpInputStream in = get(location, false, false);
          try {
              if (in.getStatusCode() == 302) {
                  Header h = in.getResponseHeader("location");
                  if (h != null) {
                      return new URL(h.getValue());
                  }
              }
              return null;
          } finally {
              try {
                  in.close();
              } catch (Exception e) {
              }
          }
      }
docs: Ping the given endpoint to see if an HTTP 302 status code is returned. If
  so, return the location given in the HTTP response header. If not, return
  null.