import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
public class client {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
// System.getProperties().setProperty("proxySet", "true");
System.getProperties().setProperty("http.proxyHost","172.19.4.42");
System.getProperties().setProperty("http.proxyPort","8080");
URL u = new URL("http://www.163.com");
URLConnection uc = u.openConnection();
String contentType = uc.getContentType();
int contentLength = uc.getContentLength();
InputStream raw = uc.getInputStream();
InputStream in = new BufferedInputStream(raw);
int zimu=0;
while((zimu=in.read())!=-1)
{
System.out.print((char)zimu);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
这里需要注意的是,
System.getProperties().setProperty("http.proxyHost","172.19.4.42");
System.getProperties().setProperty("http.proxyPort","8080");
这两句如果写成:
System.getProperties().setProperty("HttpProxyHost","172.19.4.42");
System.getProperties().setProperty("HttpPoxyPort","8080");
就错了。
我们通过抓包,可以发现虽然自己没有写NTLM校验过程,但是数据包显示,设置了代理,居然自己会进行NTLM校验,不晓得为什么,(猜测似乎Java的URL已经自己实现了NTLM校验)呵呵,不过也好,省去了我们好多麻烦。下面想写写socks代理,看看能不能越过公司防火墙,呵呵!