HttpURLConnection, Proxies and Authentication

Discussion in 'Java' started by Roger, Jul 13, 2004.

  1. Roger

    Roger Guest

    Hi,

    I wrote a small program that establishes an HttpURLConnection to
    extract data from a web site. When I came to test it at a customer
    site - a Windows site, I discovered that a) I was sitting behind a
    proxy server and b) that the proxy server required NTLM
    authentication. A bit of googling gave me the answer to both problems
    and everything is working fine.

    However, this now begs two questions. Firstly is it possible to
    programatically determine if my program is running through a proxy
    server or is this a matter for a config file. Secondly, having
    established the answer to the first question is it possible to
    programatically determine the authentication mechanism being used by
    the proxy server, particularly given that NTLM is windows specific or
    again, is this best achieved through a config file?

    Regards
    Roger
     
    Roger, Jul 13, 2004
    #1
    1. Advertising

  2. Roger wrote:
    > However, this now begs two questions. Firstly is it possible to
    > programatically determine if my program is running through a proxy
    > server or is this a matter for a config file.


    I think you want to ask something different. But first to your
    questions: If your program is already running through a proxy, someone
    must have configured the program's proxy settings correctly, otherwise
    it wouldn't run. So, because the program is configured to run with a
    proxy, this is trivial knowledge. You could e.g. check the particular
    system properties in Java.

    But I guess you would like to know if a program can figure out if it is
    supposed to use a proxy and what the necessary settings are.
    Unfortunately, there is no portable way in Java to do this. This is an
    application specific configuration. If you are on windows, you could use
    JNI and do what other Windows programs do, too: They snoop the IE
    configuration data and take the same data, assuming someone correctly
    configured IE.

    I am sure there are also a few libraries out there providing such an
    implementation.


    > Secondly, having
    > established the answer to the first question is it possible to
    > programatically determine the authentication mechanism being used by
    > the proxy server,


    The 407 response should contain information about the authentication
    scheme in a HTTP header. I have no idea if your particular Windows proxy
    provides this.

    I highly suggest you spend some time reading the HTTP 1.0 and 1.1 RFCs
    to learn the details. And get some network sniffer. Such a tool comes
    very handy if you need to find the difference between theory and real
    implementation.

    /Thomas
     
    Thomas Weidenfeller, Jul 13, 2004
    #2
    1. Advertising

  3. Roger

    Chris Smith Guest

    Roger wrote:
    > However, this now begs two questions. Firstly is it possible to
    > programatically determine if my program is running through a proxy
    > server or is this a matter for a config file. Secondly, having
    > established the answer to the first question is it possible to
    > programatically determine the authentication mechanism being used by
    > the proxy server, particularly given that NTLM is windows specific or
    > again, is this best achieved through a config file?


    There are two standards out there, called WPAD and PAC, which can be
    combined to discover the correct proxy settings on large networks if the
    network administrator has set things up correctly. Otherwise, you'll
    have to rely on the user knowing their proxy config. If there is no
    WPAD or PAC on the network, that means that the user must have manually
    configured their proxy settings for IE and such, too, so you can ask
    them to look there.

    It does make sense, by the way, to support PAC but not WPAD... however,
    WPAD implies PAC so that the other direction doesn't work. Implementing
    PAC requires an embedded JavaScript interpreter such as
    http://www.mozilla.org/rhino/.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Jul 13, 2004
    #3
  4. Roger

    Daniel Hagen Guest

    Roger wrote:
    > However, this now begs two questions. Firstly is it possible to
    > programatically determine if my program is running through a proxy
    > server or is this a matter for a config file. Secondly, having


    For windows there are system properties you can query (http.proxyHost,
    http.proxyPort, proxySet if my memory is correct).
    From my experience though, these are unreliable since they don't
    include the "do not use proxy server for this addresses..." - list.

    Regards

    Daniel
     
    Daniel Hagen, Jul 13, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Taylor

    Java and proxies

    Paul Taylor, Jun 28, 2005, in forum: Java
    Replies:
    0
    Views:
    342
    Paul Taylor
    Jun 28, 2005
  2. -
    Replies:
    0
    Views:
    430
  3. Frank Natoli

    HttpURLConnection and GET

    Frank Natoli, Aug 22, 2005, in forum: Java
    Replies:
    10
    Views:
    12,134
    Raymond DeCampo
    Aug 24, 2005
  4. Lothar Scholz

    httplib and proxies

    Lothar Scholz, Jun 3, 2004, in forum: Python
    Replies:
    2
    Views:
    365
    Colin Brown
    Jun 4, 2004
  5. Fuzzyman

    urllib2, https, and proxies

    Fuzzyman, Jun 29, 2005, in forum: Python
    Replies:
    0
    Views:
    424
    Fuzzyman
    Jun 29, 2005
Loading...

Share This Page