I'd like to access a file that is protected by .htaccess in my Android app. Below is what I need to get just a file, but not .htaccess protected. I don't know where I can put my credentials... Can someone help me with adding credentials to this? Or propose another way to collect the file? Thanks in advance :)
InputStream inputStream = null;
URL url = null;
try {
url = new URL(THENEEDEDURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("GET");
conn.setDoInput(true);
// Starts the query
conn.connect();
inputStream = conn.getInputStream();
InputStreamReader reader = new InputStreamReader(inputStream);
Gson gson = new GsonBuilder().create();
winnendeCodes = gson.fromJson(reader, WedstrijdCode[].class);
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
You need to use
setRequestProperty
on yourHttpURLConnection
object: