I am trying to connect to a web site that uses SSL. This connection is via proxy (squid) that also requires proxy authentication.
I am currently using HttpsUrlConnection for connections within my app and would prefer to continue to use this if it is possible.
The problem occurs when you make the connection using connection.open("https://domain.com"), the HTTP CONNECT is sent immediately before you have had a chance to set any headers including "Proxy-Authentication", in a normal http connection nothing is sent until getOutputStream is called, so just setting this header works.
It is possible to set a defaultAuthenticator for this that returns the correct name and password. There are two problems with this though:
The application is a web application running inside a web server with unknown other applications. If I set a default authenticator, would this effect other applications? (for the same reason setting system properties is out)
I also need the ability to use different proxies in different connections. e.g. I may have a connection that goes to proxy1.domain.com and another that goes to proxy2.domain.com, each with different credentials.
What is the correct way of achieving this? I would be very surprised if this was not possible for HttpUrlConnection given its widespread use.