I'm trying to find how to do some Http Request in Android 6.0,
Since Android go to the 6.0 version, I can't find anything to help me with the 6.0 changes.
I just wanna do some HTTP request to an REST Api without any dependencies
I've done this but its return me 405 instead of 200.
@Override
protected Object doInBackground(Object[] params) {
public String rest_Url = "https://balblabla" ;
HttpURLConnection client = null;
try {
URL url = new URL(rest_Url);
client = (HttpURLConnection) url.openConnection();
if (client != null){
client.setRequestMethod("GET");
// client.setRequestProperty("Accept-Encoding", "identity");
client.setDoOutput(true);
}
OutputStream outputPost = new BufferedOutputStream(client.getOutputStream());
outputPost.flush();
if (outputPost!= null){outputPost.close();}
int responseCode = client.getResponseCode();
if (responseCode != 200){
String failure = "ECHEC";
System.out.println(failure);
}else {
String success = "BRAVO";
System.out.println(success);
}
} catch (IOException e) {e.printStackTrace();}
finally {
if(client != null){
client.disconnect();
}
}
return null;`
Thanks for your answers.