I try to download a file from a URL and save it locally in java. This URL works from my browser but in JAVA, I got these exeception : java.net.SocketException: Connection reset.
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:658)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1323)
at java.net.URL.openStream(URL.java:1037)
I tried with different implementations :
Apache Common IO:
Files.copy(myUrl.openStream(), file, StandardCopyOption.REPLACE_EXISTING);
Jersey 2 :
WebTarget target =ClientBuilder.newClient().target(myUri);
Response response = target.path(ressourcePath).request().get();
Java io :
URL link = new URL(myUri);
InputStream in = new BufferedInputStream(link.openStream());
All these examples throw a java.net.SocketException: Connection reset Exception.
I have no control on the server who send the file.