设计 工具 系统 开发 安全 办公 陶吧 IT教育 Vista频道|Google Chrome SOA案例研究
您现在的位置: 天极网 > 软件频道 > IT教育频道 > 培训辅导 > Java程序如何穿透带有密码验证的代理
全文

Java程序如何穿透带有密码验证的代理

2005-09-22 15:01作者:出处:ChinaITLab责任编辑:王玉涵

  网上也有一些文章但是大多数涉及带有授权验证的proxy都有问题,主要问题就是出在对Authenticator.setDefault的使用,以及base64编码的问题上代码是最没有二义性的文档,实现原理不再解释,请看代码去体会。

  ackage org.chimae.net;

  import java.io.BufferedReader;

  import java.io.IOException;

  import java.io.InputStream;

  import java.io.InputStreamReader;

  import java.net.Authenticator;

  import java.net.HttpURLConnection;

  import java.net.PasswordAuthentication;

  import java.net.URL;

  /**

  * @author chimae@cnjsp.org

  */

  ublic class ProxyConnTest {

  ublic static void initProxy(String host, int port, final String username,

  final String password) {

  Authenticator.setDefault(new Authenticator() {

  rotected PasswordAuthentication getPasswordAuthentication() {

  return new PasswordAuthentication(username,

  ew String(password).toCharArray());

  }

  });

  System.setProperty(\"http.proxyType\", \"4\");

  System.setProperty(\"http.proxyPort\", Integer.toString(port));

  System.setProperty(\"http.proxyHost\", host);

  System.setProperty(\"http.proxySet\", \"true\");

  }

  ublic static void main(String[] args) throws IOException {

  String url = \"http://java.sun.com/\";

  String proxy = \"yourProxy\";

  int port =8080;

  String username =\"username\";

  String password =\"password\";

  String curLine = \"\";

  String content = \"\";

  URL server = new URL(url);

  initProxy(proxy,port,username,password);

  HttpURLConnection connection = (HttpURLConnection)server.openConnection();

  connection.connect();

  InputStream is = connection.getInputStream();

  BufferedReader reader = new BufferedReader(new InputStreamReader(is));

  while ((curLine = reader.readLine()) != null) {

  content += curLine;

  }

  System.out.println(\"content= \" + content);

  is.close();

  }

  }


  阅读关于 proxy base64编码 的全部文章
共1页。 1
相关搜索:
相关文章及软件
关注此文读者还看过
热门关注
特别推荐
文章排行
本周
本月
最近更新
关于我们|网站律师|天极服务|电子杂志|RSS订阅|加入我们|网站地图
TMG
Copyright (C) 1999-2008 Chinabyte.com, All Rights Reserved 版权所有 天极网络
商务联系、网站内容、合作建议:010-82657868
版权声明 在线提交意见反馈 Powered by 天极内容管理平台CMS4i
经营性网站备案信息 网警备案 中国网站排名
天极传媒:天极网|比特网|IT专家网|IT商网|52PK游戏网|IT分众