利用Authenticator技术访问proxy外部http server

来源:互联网 发布:北京哪有淘宝拍照的店 编辑:程序博客网 时间:2024/06/07 00:44
<script type="text/javascript">google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";google_ad_width = 336;google_ad_height = 280;//</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>利用Authenticator技术访问外部http server。import java.io.*;import java.net.*;import java.awt.*;import java.awt.event.*;public class URLPassword extends Frame {private TextField tf = new TextField();private TextArea ta = new TextArea();public URLPassword() {super ("URL Password");// 安装 AuthenticatorAuthenticator.setDefault (new MyAuthenticator ());// 设置屏幕add (tf, BorderLayout.NORTH);ta.setEditable(false);add (ta, BorderLayout.CENTER);tf.addActionListener (new ActionListener() {public void actionPerformed (ActionEvent e) {String s = tf.getText();if (s.length() != 0)ta.setText (fetchURL (s));}});addWindowListener (new WindowAdapter() {public void windowClosing (WindowEvent e) {dispose();System.exit(0);}});}private String fetchURL (String urlString) {StringWriter sw = new StringWriter();PrintWriter pw = new PrintWriter(sw);try {URL url = new URL (urlString);InputStream content = (InputStream)url.getContent();BufferedReader in =new BufferedReader (new InputStreamReader (content));String line;while ((line = in.readLine()) != null) {pw.println (line);}} catch (MalformedURLException e) {pw.println ("Invalid URL");} catch (IOException e) {pw.println ("Error reading URL");}return sw.toString();}public static void main (String args[]) {Frame f = new URLPassword();f.setSize(300, 300);f.setVisible (true);}class MyAuthenticator extends Authenticator {protected PasswordAuthentication getPasswordAuthentication() {final Dialog jd = new Dialog (URLPassword.this, "Enter password", true);jd.setLayout (new GridLayout (0, 1));Label jl = new Label (getRequestingPrompt());jd.add (jl);TextField username = new TextField();username.setBackground (Color.lightGray);jd.add (username);TextField password = new TextField();password.setEchoChar ('*');password.setBackground (Color.lightGray);jd.add (password);Button jb = new Button ("OK");jd.add (jb);jb.addActionListener (new ActionListener() {public void actionPerformed (ActionEvent e) {jd.dispose();}});jd.pack();jd.setVisible(true);String pass= new String(password.getText());return new PasswordAuthentication (username.getText(),pass.toCharArray());}}}
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 无限岩浆怎么做 岩浆岩的形成 拳皇2002七枷社岩浆拳 岩溶 兴国太平岩溶洞 复方岩白菜素 片麻岩 岩白菜素片 片岩 岩片漆价格 岩片漆配方 岩片真石漆价格 染色岩片 片麻岩由什么变质而来 天然岩片 片麻岩是什么岩 复合岩片厂家 岩片真石漆厂家 岩片厂家 外墙岩片真石漆价格 复合岩片配方 岩片漆报价 岩片漆图片 石头漆 夜光粉 岩田粘度杯 岩田 岩田自动喷漆枪 贺兰山岩画 花山岩画 岩画 阴山岩画 贺兰山岩画旅游 桌子山岩画旅游 贺兰山岩画风景区 银川贺兰山岩画 岩盐 岩盐是什么 岩盐芝士 岩盐气溶胶 岩盐矿