KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > NtlmHttpClient


1 import java.io.*;
2
3 import java.net.*;
4
5 import jcifs.*;
6
7 public class NtlmHttpClient {
8
9     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
10         // Normally set this outside application.
11
// Note that as a side effect due to the way handlers are located,
12
// you can also achieve this by simply doing:
13
Config.registerSmbURLHandler();
14         // which we already do to register the smb handler.
15
//String pkgs = System.getProperty("java.protocol.handler.pkgs");
16
//pkgs = (pkgs != null) ? "jcifs|" + pkgs : "jcifs";
17
//System.setProperty("java.protocol.handler.pkgs", pkgs);
18
//
19

20         if (args == null || args.length < 4) {
21             System.out.println("NtlmHttpClient <url> <domain> <user> <password>");
22             System.exit(1);
23         }
24         String JavaDoc location = args[0];
25         String JavaDoc domain = args[1];
26         String JavaDoc user = args[2];
27         String JavaDoc password = args[3];
28         // can also specify these in the URL, i.e.
29
// http://DOMAIN%5cuser:password@host/dir/file.html
30
// which will override these properties
31
Config.setProperty("jcifs.smb.client.domain", domain);
32         Config.setProperty("jcifs.smb.client.username", user);
33         Config.setProperty("jcifs.smb.client.password", password);
34
35         try {
36             Config.setProperty("jcifs.netbios.hostname",
37                     Config.getProperty("jcifs.netbios.hostname",
38                             InetAddress.getLocalHost().getHostName()));
39         } catch (Exception JavaDoc ex) { }
40         URL url = new URL(location);
41         BufferedReader reader = new BufferedReader(
42                 new InputStreamReader(url.openStream()));
43         String JavaDoc line;
44         while ((line = reader.readLine()) != null) {
45             System.out.println(line);
46         }
47     }
48
49 }
50
Popular Tags