Guest User

Untitled

a guest
Nov 18th, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public static JSONObject getJSONObjectFromURL(String urlString) throws IOException, JSONException, MalformedURLException, ProtocolException {
  2. HttpURLConnection urlConnection = null;
  3. URL url = new URL(urlString);
  4.  
  5. urlConnection = (HttpURLConnection) url.openConnection();
  6.  
  7. urlConnection.setRequestMethod("GET");
  8. urlConnection.setReadTimeout(10000 /* milliseconds */ );
  9. urlConnection.setConnectTimeout(15000 /* milliseconds */ );
  10. urlConnection.setDoOutput(true);
  11. urlConnection.connect();
  12.  
  13. int statusCode = urlConnection.getResponseCode();
  14.  
  15. System.out.println("CODIGOOOOOOOO:"+statusCode);
  16.  
  17. BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
  18. StringBuilder sb = new StringBuilder();
  19.  
  20. String line;
  21. while ((line = br.readLine()) != null) {
  22. sb.append(line + "n");
  23. }
  24. br.close();
  25.  
  26. String jsonString = sb.toString();
  27. System.out.println("JSON: " + jsonString);
  28.  
  29. return new JSONObject(jsonString);
  30. }
  31.  
  32. java.io.FileNotFoundException: http://192.168.0.12/projeto/Cadastrarformularios.php?json=[{"Modalidade":"Presencial","Unidade":"belem","Email":"1@d.com","CPF":"1","Sobrenome":"sobrenome","Fone":"1","Cod_Consultor":"1001","Data_Cadastro":"2017-11-18 22:49:40","Curso":"autonomia","Nome":"1","Celular":"1"}]
Add Comment
Please, Sign In to add comment