开发者

How to authenticate Java to fetch URL

开发者 https://www.devze.com 2023-02-04 08:12 出处:网络
I want to fetch a URL with java.net but any connection is refused. I know that when I ask for a page, my browser (IE) uses my Windows login ID to authenticate me, then pass my requ开发者_JAVA百科est t

I want to fetch a URL with java.net but any connection is refused. I know that when I ask for a page, my browser (IE) uses my Windows login ID to authenticate me, then pass my requ开发者_JAVA百科est through a proxy. Can someone please help me translate this process into the Java libraries and steps to fetch webpage? Thank you.

EDIT: - I'm not sure what kind of authentication it uses here. Before any page is retrieved, it pops up a login window where I have to type in my domain\userid and password. How can I figure out the type of authentication?

- The proxy changes via an automatic configuration script.


I recommend you use HttpClient, which makes authentication very simple:

http://hc.apache.org/httpclient-3.x/authentication.html

It's not clear from your question what exactly the role of the proxy is here in authenticating you, but a combination of HttpClient + the right headers (if you need them) should be sufficient.


You can configure the Java runtime to use a proxy for Network comms. See this article.


You may want to try

java.net.Authenticator.setDefault(yourCustomAuthenticator);
0

精彩评论

暂无评论...
验证码 换一张
取 消