Check out the official site of Unirest at http://kong.github.io/unirest-java
In this page, I only introduce the basic usage of Unirest.
<dependency> <groupId>com.konghq</groupId> <artifactId>unirest-java</artifactId> <version>2.3.17</version></dependency>HttpResponse<String> response = Unirest.get("http://httpbin.org") .header("Accept", "application/json") .queryString("flower", "lotus") //optional request param .queryString("origin", "vietnam") //optional request param .asString();// Results in "http://httpbin.org?flower=lotus&origin=vietnam"The HttpResponse<type> inside diamond bracket can be:
HttpResponse<String> httpResponse = Unirest.post("http://longdothanh.com") .body("JSON body") .header("Content-Type", "application/json") .asString();Unless you specify otherwise the default Content-Type is text/plain; charset=UTF-8
Unirest.post("http://httpbin.org") .field("flower", "lotus") .field("origin", "vietnam") .asEmpty(); // This will post a simple name-value pair body the same as a HTML form. This looks like // `flower=lotus&origin=vietnam'