Is it possible to download a file with JSON data inside it from a URL? Also, the files I need to get have no file extension, is this a problem or can i force it to have a .txt extension upon download?
UPDATE: I forgot to mention, that the website requires a username and password entered in order to access the site which i know. There a way to input these values in as I retrieve the file?
Have you tried using URLConnection?
private InputStream getStream(String url) {
try {
URL url = new URL(url);
URLConnection urlConnection = url.openConnection();
urlConnection.setConnectTimeout(1000);
return urlConnection.getInputStream();
} catch (Exception ex) {
return null;
}
}
Also remember to encode your params like this:
String action="blabla";
InputStream myStream=getStream("http://www.myweb.com/action.php?action="+URLEncoder.encode(action));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With