Hello, I'm developing a project where I need to get and send values to a server. I did everything and it worked perfectly in version 7.0 of the android, but when going to 4.2, it starts giving error.
I'm using an Asynctask to make the request, sending and receiving response from the server.
public static JSONObject getJSONObjectFromURL(String urlString) throws IOException, JSONException, MalformedURLException, ProtocolException {
HttpURLConnection urlConnection = null;
URL url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(10000 /* milliseconds */ );
urlConnection.setConnectTimeout(15000 /* milliseconds */ );
urlConnection.setDoOutput(true);
urlConnection.connect();
int statusCode = urlConnection.getResponseCode();
System.out.println("CODIGOOOOOOOO:"+statusCode);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
String jsonString = sb.toString();
System.out.println("JSON: " + jsonString);
return new JSONObject(jsonString);
}
But I'm getting the following error:
java.io.FileNotFoundException: http://192.168.0.12/projeto/Cadastrarformularios.php?json=[{"Modalidade":"Presencial","Unidade":"belem","Email":"[email protected]","CPF":"1","Sobrenome":"sobrenome","Fone":"1","Cod_Consultor":"1001","Data_Cadastro":"2017-11-18 22:49:40","Curso":"autonomia","Nome":"1","Celular":"1"}]
By the time I realized it, the 400 error is returning, but I do not know why it does not work for the android, copying the link the server normally recognizes, and works normally on android 7.0
@edit In version 6.0 also does not catch, only in 7.0
NOTE: For some reason, the user can log in, he can log in normally and the code for authentication is the same one posted. Thanks in advance for the help!