1

I'm trying to download a file which is behind a website with authentication. The service gave an example script which uses wget to download the file.

Now I'm trying to mimic that functionality in Java

set WGET_PARAM= --no-check-certificate --secure-protocol=TLSv1
set DOWNLOAD_PARAM=-nd -N -r --level=2 --include-directories=blob --accept=csv,txt,zip %PAGE%

REM * wget --save-cookies cookies.txt  %WGET_PARAM% --keep-session-cookies --post-data %ACCOUNT% -O NUL https://www.example.com!login
wget --load-cookies cookies.txt  %WGET_PARAM%  %DOWNLOAD_PARAM% 
REM * wget --load-cookies cookies.txt  %WGET_PARAM% --post-data="x=1"  -O https://www.example.com!logout

Any idea how I get around the --no-check-certificate --secure-protocol=TLSv1 ?

Thanks for any help.

FreshMike
  • 481
  • 1
  • 6
  • 26
  • 1
    What have you done so far in Java? – Josh Chappelle Dec 11 '15 at 17:57
  • 1
    First, see this answer to bypass the cert check: http://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https/5297100#5297100 Then this one for the login: http://stackoverflow.com/questions/496651/connecting-to-remote-url-which-requires-authentication-using-java And this one for the cookie: http://stackoverflow.com/questions/16150089/how-to-handle-cookies-in-httpurlconnection-using-cookiemanager – Andrew Henle Dec 11 '15 at 22:16

2 Answers2

0

Here is a library that does it and provides an example of how to use it.

https://github.com/axet/wget

Josh Chappelle
  • 1,558
  • 2
  • 15
  • 37
  • 1
    That won't get me past the SSL and login. Looks like this lib does basically FileUtils.copyInputStreamToFile or FileUtils.copyURLToFile. Thanks for the tip anyway. – FreshMike Dec 15 '15 at 13:18
0

I have done what @Andrew Henle has suggested. One issue I had was to get the session-cookie. The solution was to use

 httpsConnection.setInstanceFollowRedirects(false);

also this helped: To be able to see Set-Cookie values in HttpURLConnection.getHeaderFields, one should not set up a CookieManager.

https://bugs.openjdk.java.net/browse/JDK-8036017

FreshMike
  • 481
  • 1
  • 6
  • 26