This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes How to authenticate HttpURLConnection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to authenticate HttpURLConnection?" Watch "How to authenticate HttpURLConnection?" New topic
Author

How to authenticate HttpURLConnection?

Mattew Force
Greenhorn

Joined: May 03, 2007
Posts: 16
Hi,

I am trying to find out how the *beep* my servlet can authenticate a HttpURLConnection but I only end up in frustration. The servlet is running on the intranet but sometimes it needs to access data e.g. from URLs outside the net and then the browser should ask the user for authorization to the proxy server in order to get the input stream from the connection. See the following code:



But of course this fails. I have seen examples where they do:



And it actually worked, but I don't want to hard-code some username and password because the servlet should restrict users which don't have access.

I also tried solving this by redirecting to the url we want to read from to trigger the proxy authentication in the browser but that didn't work.

This is probably a very stupid question but this is only my second servlet so I'm sure there are people here who knows better

Hope someone can help me.

/M
 
 
subject: How to authenticate HttpURLConnection?