免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5628 | 回复: 16
打印 上一主题 下一主题

http proxy + authentication的使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-08 13:21 |只看该作者 |倒序浏览
对于java.lang.reflect.Proxy谈谈大家如何使用的
可能是由于有代理的原因,我编写的程序中的超链接,不能连上外部的网站,所以想用这个解决,但是没有思路,谢谢大家的支持,也是一起学习的过程

[ 本帖最后由 perryhg 于 2006-3-17 21:38 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-03-09 11:48 |只看该作者
此代理非彼代理也~~

论坛徽章:
0
3 [报告]
发表于 2006-03-09 12:42 |只看该作者
这个Proxy是动态代理模式,是一个Design Pattern,不是internet proxy

论坛徽章:
0
4 [报告]
发表于 2006-03-09 13:23 |只看该作者
程序启动的时候用 java -Dhttp.proxyHost=192.168.0.1 -Dhttp.proxyPort=3128 myapp

论坛徽章:
0
5 [报告]
发表于 2006-03-09 18:30 |只看该作者
谢谢大家,能告诉我,应该用哪个代理类作呀,谢谢了,是不是这个java.net.Authenticator,找了很久,都没有思路

论坛徽章:
0
6 [报告]
发表于 2006-03-09 21:05 |只看该作者
1.5中有java.net.Proxy类

论坛徽章:
0
7 [报告]
发表于 2006-03-09 21:44 |只看该作者
楼主用IE或者Firefox直接访问那个网页的话,需要代理么?如果不需要,JEditorPane也应该不需要;

如果需要的话,请用perryhg斑竹的方法

[ 本帖最后由 sakulagi 于 2006-3-9 21:47 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2006-03-10 09:15 |只看该作者
用浏览器,也会出现代理那个对话框

论坛徽章:
0
9 [报告]
发表于 2006-03-10 09:17 |只看该作者

我用英语说说这个问题吧,这个问题国外很多人也在问

Hello to all Ranchers
this is my first post..

now coming to my problem--

I'm trying to make a simple browser for my application and of many options i choose JEditorPane to implement the browser.

When i try to execute the program i get the following error:

java.io.IOException: Authentication failure
at sun.net.www.protocol.http.HttpURLConnect ... onnection.java:649)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:272)
at javax.swing.JEditorPane.getStream(JEditorPane.java:674)
at javax.swing.JEditorPane.setPage(JEditorPane.java:392)
at javax.swing.JEditorPane.setPage(JEditorPane.java:775)
at SwingExamples.EditorPaneFrame.jbInit(EditorPaneFrame.java:41)
at SwingExamples.EditorPaneFrame.<init>(EditorPaneFrame.java:17)
at SwingExamples.EditorPaneFrame.main(EditorPaneFrame.java:50)

I connect to internet through a Web Proxy which needs authentication.
After searching the net and through this forum i found that java.net.Authenticator can be used to provide authentication details.

This is the code i have written:


code:
--------------------------------------------------------------------------------

..............    System.setProperty( "proxySet", "true" );    System.setProperty( "http.proxyHost", "proxyhost" );    System.setProperty( "http.proxyPort", "proxyport" );    Authenticator.setDefault(new SampleAuthenticator());        jEditorPane1.setPage("http://www.google.com");................ class SampleAuthenticator extends Authenticator  {    public PasswordAuthentication getPasswordAuthentication()    {      return new PasswordAuthentication("myUserName", "myPass".toCharArray() );    }  }................

--------------------------------------------------------------------------------



I get the same error even after i use the Authenticator. The JEditorPane establishes a HttpURLConnection by itself, so will it know about the proxy setting and also the authentication detials that i have set?

Any suggestions!!!

论坛徽章:
0
10 [报告]
发表于 2006-03-10 09:18 |只看该作者
谢谢大家的关注,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP