401 when getting response

B

ben

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
 
T

Thomas Weidenfeller

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top