1. Get请求
1.1 安装依赖库
依赖库 Okhttp3
,非常流行的HTTP库,可以简单、快速实现HTTP调用。
方法:在 pom.xml 文件中添加依赖:
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.1.0</version>
</dependency>
唯一的 <dependencies>
标签中,包含多个dependency
标签,每一个<dependency>
标签都是一个依赖库,在进行依赖库添加时要注意顺序。
1.2 依赖库的使用使用
- 实例化
OkHttpClient
OkHttpClient okHttpClient = new OkHttpClient();
- 执行调用