We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 21f061f commit f5ad152Copy full SHA for f5ad152
1 file changed
02nio/okhttpdemo/okhttpdemo/src/main/java/com/geekbang/okhttpdemo/work/OkHttpDemo.java
@@ -0,0 +1,28 @@
1
+package com.geekbang.okhttpdemo.work;
2
+
3
+import okhttp3.OkHttpClient;
4
+import okhttp3.Request;
5
+import okhttp3.Response;
6
7
+import java.io.IOException;
8
9
+public class OkHttpDemo {
10
+ final OkHttpClient client = new OkHttpClient();
11
12
+ String getUrl(String url) throws IOException {
13
+ Request request = new Request.Builder()
14
+ .url(url)
15
+ .build();
16
17
+ try (Response response = client.newCall(request).execute()) {
18
+ return response.body().string();
19
+ }
20
21
22
23
+ public static void main(String[] args) throws IOException {
24
+ OkHttpDemo okHttpDemo = new OkHttpDemo();
25
+ String response = okHttpDemo.getUrl("http://localhost:8801");
26
+ System.out.println(response);
27
28
+}
0 commit comments