Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

How to authenticate HttpURLConnection?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't MAKE me come back there with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic