401 when getting response

Discussion in 'Java' started by ben, Aug 12, 2003.

  1. ben

    ben Guest

    Hi,

    I'm trying to connect to a server with HttpUrlConnection to send an
    xml transaction.

    When I go through the browser to the url, I get a popup box. I enter
    domainname\username and the password and I'm allowed to see the page.

    When I go through the code, it seems fine when I make a request but as
    soon as I try to get the response, I get this :
    java.io.FileNotFoundException: Response: '401: Unauthorized xxx'

    Here's part of the code when I do the authentication :
    --------------
    String userPassword= domainName + "username:password";
    String encoding= new sun.misc.BASE64Encoder().encode
    (userPassword.getBytes()); conn.setRequestProperty("Authorization",
    "Basic " + encoding);

    conn.setRequestMethod("POST"); // btw, should this be a get?
    --------------

    I read that modifying the system properties might help but it didn't :

    // System.getProperties().put( "http.proxySet", "true" );
    // System.getProperties().put( "http.proxyHost", "proxyname" );
    // System.getProperties().put( "http.proxyPort", "80" );

    Thanks for any help you can provide!

    Ben
    ben, Aug 12, 2003
    #1
    1. Advertising

  2. (ben) writes:
    > When I go through the code, it seems fine when I make a request but as
    > soon as I try to get the response, I get this :
    > java.io.FileNotFoundException: Response: '401: Unauthorized xxx'


    401 is the response sent by the server to challenge the
    authentication. You should respond to it with the credentials. And(!)
    you should provide that data without additional challenges as long as
    you try to access the same protection space (but not at all if the
    it changes), to avoide more 401 responses.

    I guess you might want to study RFC 2617 (or any newer version, if any)
    in more detail.

    /Thomas
    Thomas Weidenfeller, Aug 13, 2003
    #2
    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. kackson

    webservice response with 401

    kackson, May 8, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    107
    kackson
    May 8, 2004
  2. Alex Washtell via .NET 247

    Web Service + Anon Access, but getting 401 Access Denied Error

    Alex Washtell via .NET 247, Apr 5, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    190
    Mauro Ottaviani [MSFT]
    Apr 5, 2005
  3. Adam Tauno Williams

    Can't get around HTTP/401 response using SUDS

    Adam Tauno Williams, Mar 8, 2012, in forum: Python
    Replies:
    0
    Views:
    323
    Adam Tauno Williams
    Mar 8, 2012
  4. Adam Tauno Williams
    Replies:
    0
    Views:
    518
    Adam Tauno Williams
    Mar 10, 2012
  5. iMath
    Replies:
    3
    Views:
    131
    iMath
    Jan 7, 2013
Loading...

Share This Page