I must simulate in java the following wget command:
wget.exe --no-check-certificate --user utente --password pordine - https://x.x.x.x:YYYY/jsonContent
I almost did it, but something is wrong because - i suppose - I cannot set the option --no-check-certificate that i had in the command-line command.
Here my main:
//main
URL url;
try {
url = new URL("https://x.x.x.x:YYYY/jsonContent");
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
String userPassword = "utente:pordine";
String encoded = Base64.getEncoder().encodeToString((userPassword).getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic "+encoded);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", acceptProperty);
//hOW TO SIMULATE THE OPTION --no-check-certificate ?
System.out.println("Response Code : " + conn.getResponseCode()); //500
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} catch ...
And... here's the errors i get:
java.io.IOException: Server returned HTTP response code: 500 for URL: https://x.x.x.x:YYYY/basicAuth
== UPDATE ==
I went back to the problem; I modified the server part to give additional logs I am closer to the root cause. The server has a class to manage the authentication: AuthManager. This is injected so I overwrote the constructor of this class in order to log every time it's called.
When I access the URL by browser, the constructor AuthManager() is called once, and values about authentication are kept during the whole session. But when i access the same URL through my script, the constructor is called twice: after the first call some informations are set in the AuthManager but later the object is overwritten by the second call to the constructor. The new object will not have some variables set, and when those data are required, the exception is launched.
Any idea how to change my script in order to ? I will try to go on and write more info. It seems i need something like a singleton for the session - or something like that...