httpclient在3x版本中是支持ntlm认证的,但是在4.0版本中确不支持了,不知道是什么原因?现在我用httpclient4.0版本做个客户端,但是需要设置代理,而代理需要ntlm认证的,我知道在jdk6.0以后的版本新的特性中支持ntlm的,不知道怎么才能让httpclient4.0也支持ntlm认证,希望各位能给出例子,谢谢!同时使用httpclient3.x版本进行ntlm认证时,提示说是org.apache.commons.httpclient.HttpMethodDirector中的错误
在请求时被服务器拒绝,估计是写错了关于httpclient3.x的ntlm一直没有找到用法,不知道各位老大能不能给个例子,让我参考一下
谢谢了!!!!

解决方案 »

  1.   

    http://hc.apache.org/httpclient-3.x/authentication.html#Authentication_Schemes
      

  2.   

    httpclient是什么东东?我一直把浏览器当作http的client
      

  3.   

    这个问题倒是研究过一次,不过最后发现JDK1.5、1.6已实现了,所以没必要用Apache的httpclient了。分为两种
    1).你的机器是加入Domain的
    2).一种是你的机器是不加入Domain的
    private String openURL_NTLM(String urlString) throws IOException {
            StringBuffer buf = new StringBuffer();
            URL url = new URL(urlString);        Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("domain\\name", "pass".toCharArray());
                }
            });      InputStream in = url.openConnection().getInputStream();       while (in.available() > 0) {
                byte[] b = new byte[in.available()];
                int result = in.read(b);
                if (result == -1) break;
                buf.append(new String(b));
            }
            return buf.toString();
        }    private String openURL_NTLM_Proxy(String urlString) throws IOException {
            StringBuffer buf = new StringBuffer();
            URL url = new URL(urlString);        Authenticator.setDefault(new Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("domain\\user", "pass".toCharArray());
                }
            });        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.getByName("xx.xx.xx.xx"), 8080));
            HttpURLConnection http = new HttpURLConnection(url, proxy);        http.setRequestProperty("Proxy-Authorization", new
                    BASE64Encoder().encode("domain\\user:pass".getBytes()));        http.connect();        InputStream in = http.getInputStream();
            while (in.available() > 0) {
                byte[] b = new byte[in.available()];
                int result = in.read(b);
                if (result == -1) break;
                buf.append(new String(b));
            }
            return buf.toString();
        }
      

  4.   

    另外一点是Apache的httpclient后来就不支持NTLM的1.3版本了,所以是没用的
      

  5.   

    Currently HttpClient 4.0 does not provide support for the NTLM authentication scheme out of the box and probably never will. The reasons for that are legal rather than technical.
      

  6.   

    用的是jdk1.6、httpclient-4.0.1和jcifs-1.3.14访问ntlm认证的系统,在本机上是可以访问的,部署在linux服务器上,用了一次是可以的,后来不行了,在请求时被服务器拒绝,请问是什么原因呀?主要技术参考是如下网址
    http://hc.apache.org/httpcomponents-client/ntlm.html提示信息如下
    Server returned HTTP response code: 401 for URL: