I want to download a binary file from a webserver which is running on a embedded device. That file can be downloaded manually after a basic http authentication by using that
URL: http://10.10.10.10/config.bin
... Now i want to automate this process with a simple Java application. By using the basic java tools i managed to download the file:
URL mlrrl = new URL(url);
HttpURLConnection con = (HttpURLConnection) mlrUrl.openConnection();
con.setRequestMethod("GET");
con.setAllowUserInteraction(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setConnectTimeout(10000);
con.setRequestProperty("Authorization", "Basic " + authStringEnc);
InputStream stream = con.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("configDown.bin");
BufferedOutputStream out = new BufferedOutputStream(file);
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.flush();
That seemed to work fine! In comparison with the manually (by Browser-Webinterface) downloaded file the generated file have the same length, but after opening both binaries with a hex-editor they were different.
My questions:
I can´t explain why, but the faulty property "setDoOutput" = "true" maybe influenced the content of the downloaded file. Setting the value to "false" solved that issue for me!