Skip to content

Commit f5ad152

Browse files
author
nononi
committed
第二周作业第6题
1 parent 21f061f commit f5ad152

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

  • 02nio/okhttpdemo/okhttpdemo/src/main/java/com/geekbang/okhttpdemo/work
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)