Java:8 OkHttp:3.7.0
Client HTTP / HTTP 2.0 pour les applications Android et Java
Pour Maven
.xml
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
</dependency>
Pour Gradle
.gradle
compile 'com.squareup.okhttp3:okhttp:3.7.0'
Java 7 et supérieur
Get Flux de processus
.java
String url = "http://www.casareal.co.jp";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(url).build();
Call call = client.newCall(request);
Response response = call.execute();
ResponseBody body = response.body();
Si vous l'écrivez simplement, vous pouvez l'écrire comme suit
.java
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
response.body().string();
POST Flux de processus
.java
OkHttpClient client = new OkHttpClient();
MediaType MIMEType= MediaType.parse("application/json; charset=utf-8");
RequestBody requestBody = RequestBody.create (MIMEType,"{}");
Request request = new Request.Builder().url(url).post(requestBody).build();
Response response = client.newCall(request).execute();
http://square.github.io/okhttp/