Created
March 28, 2019 21:37
-
-
Save vacax/c7fcfa6498e3f82cfbfa9652d34ffc19 to your computer and use it in GitHub Desktop.
Ejemplo cliente Unirest Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HttpResponse<JsonNode> jsonResponse = Unirest.get("http://localhost:4567/rest/estudiantes/0") | |
.header("Content-Type", "application/json") | |
.header("Accept", "application/json") | |
.queryString("apiKey", "asdasgdasgd") | |
.asJson(); | |
if(jsonResponse.getStatus()==200){ | |
JsonNode objeto = jsonResponse.getBody(); | |
System.out.println(String.format("matricula : %d, nombre: %s, Carrera: %s", | |
objeto.getObject().get("matricula"), | |
objeto.getObject().get("nombre"), | |
objeto.getObject().get("carrera"))); | |
} else { | |
System.out.println("Error en al consulta: "+jsonResponse.getStatus()); | |
JSONObject object = jsonResponse.getBody().getObject(); | |
System.out.println(String.format("codigo: %d, mensaje: %s", object.get("codigo"), object.get("mensaje"))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment