<dependency> <groupId>com.mashape.unirest</groupId> <artifactId>unirest-java</artifactId> <version>1.4.9</version> </dependency> compile 'com.mashape.unirest:unirest-java:1.4.9' HttpResponse<JsonNode> response = Unirest.get("http://example.com/api/users") .header("accept", "application/json") .queryString("name", "John") .asJson(); HttpResponse<JsonNode> response = Unirest.post("http://example.com/api/users") .header("accept", "application/json") .header("Content-Type", "application/json") .body("{\"name\":\"John\", \"age\":30}") .asJson(); int statusCode = response.getStatus(); String contentType = response.getHeaders().get("Content-Type").get(0); JsonNode responseBody = response.getBody(); String name = responseBody.getObject().getString("name"); int age = responseBody.getObject().getInt("age"); try { HttpResponse<JsonNode> response = Unirest.get("http://example.com/api/users") .asJson(); } catch (UnirestException e) { e.printStackTrace(); }


上一篇:
下一篇:
切换中文