I'm trying to download an image using Java, however a 403 error code is returned:
java.io.IOException: Server returned HTTP response code: 403 for URL: https://someurl.com
I've used the command curl with the same URL and it returns OK
curl -I https://someurl.com
HTTP/1.1 200 OK Date: Tue, 11 Apr 2017 18:36:49 GMT Content-Type: image/png Content-Length: 4233029 Connection: keep-alive
This is the code I'm using to download the images:
private static boolean downloadImage(String imageURL, String path)
{
InputStream in;
try
{
URL url = new URL(imageURL);
in = new BufferedInputStream(url.openStream());
Files.copy(in, Paths.get(path), StandardCopyOption.REPLACE_EXISTING);
} catch (MalformedURLException ex) {
LOG.error(ex.toString());
return false;
} catch (IOException ex) {
LOG.error(ex.toString());
return false;
}
return true;
}
Any idea of why it fails with Java but it does work with the curl
command?
Thanks in advance,