0
Hello ,I am developing a project where I need to pick up and send values to a server. I did everything and worked perfectly in the version 7.0 of android, but when going to 4.2,begins to give error.
I’m using an Asynctask to request,sending and receiving server response.
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"}]
From what I noticed, is returning the error 400, but do not know why it does not work by android,copying the link the server recognizes normally,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 login, he can log in normally and the code for authentication is the same posted. Thanks in advance for the help !