Java:8 OkHttp:3.7.0
HTTP / HTTP 2.0 client for Android and Java applications
For Maven
.xml
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.7.0</version>
</dependency>
For Gradle
.gradle
compile 'com.squareup.okhttp3:okhttp:3.7.0'
Java 7 and above
Get Process flow
.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();
If you write it simply, you can write it as follows
.java
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
response.body().string();
POST Process flow
.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/