I am trying to get an image from an IP camera using HTTP. The camera requires basic HTTP authentication, so I have to add the appropriate request header:
URL url = new URL("http://myipcam/snapshot.jpg"); URLConnection uc = url.openConnection(); uc.setRequestProperty("Authorization", "Basic " + new String(Base64.encode("user:pass".getBytes()))); // outputs "null" System.out.println(uc.getRequestProperty("Authorization"));
I later pass the url object to ImageIO.read() , and as you can guess, I get HTTP 401 Unauthorized, although user and pass are correct.
What am I doing wrong?
I also tried new URL("http://user: pass@myipcam /snapshot.jpg") , but this also does not work.
source share