尹立民的专栏

软件工程师之家

NTLM Example

import java.io.*;
import java.net.Socket;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
 
public class NTLMFetch
{
  public static void main(String[] args) throws Exception
  {
    // Enable proxy to host logging
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
 
    // Update this to the actual URL
    String[] urll = {
                     "http://www.webstuffscan.com",
                     "http://www.csdn.net"
                  };
    int size=urll.length;
   
      HttpClient client = new HttpClient();
       
      HostConfiguration hostConfig= client.getHostConfiguration();
      // Update this to point to NTLM enabled proxy
      hostConfig.setProxy("172.16.100.25", 80);
  
      // Authenticate using NTLM
      client.getState().setProxyCredentials(AuthScope.ANY,
            new NTCredentials("lmyin","333555","172.16.100.25","ntsz"));
  for(int s=0;s<size;s++){
     HttpMethod method = new GetMethod(urll[1]);
      int statusCode = client.executeMethod(method);
      System.out.println("Stat=" +HttpStatus.getStatusText(statusCode));
      String strOutput = method.getResponseBodyAsString();
  
      // Write the output to a local file
      PrintWriter writer = new PrintWriter(new FileWriter("down"+s+".html"));
      writer.println(strOutput);
      writer.close();
   }
  }
}


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭