Ejemplo n.º 1
0
  public static void main(String args[]) throws Exception {
    String pa_name = null, pa_pass = null;

    if (args.length == 4 && "-proxy_auth".startsWith(args[0])) {
      pa_name = args[1];
      pa_pass = args[2];

      String[] tmp = {args[3]};
      args = tmp;
    }

    if (args.length != 1 || args[0].equalsIgnoreCase("-help")) {
      System.err.println("Usage: java GetAuthInfo [-proxy_auth <username> <password>] <url>");
      System.exit(1);
    }

    URI url = new URI(args[0]);

    DefaultAuthHandler.setAuthorizationPrompter(new MyAuthPrompter(pa_name, pa_pass));
    HTTPConnection con = new HTTPConnection(url);
    HTTPResponse rsp = con.Head(url.getPathAndQuery());

    int sts = rsp.getStatusCode();
    if (sts < 300) System.out.println("No authorization required to access " + url);
    else if (sts >= 400 && sts != 401 && sts != 407)
      System.out.println("Error trying to access " + url + ":\n" + rsp);
  }