http请求工具-OkHttp用法
OKHttp介绍 okhttp是一个第三方类库,用于android中请求网络。这是一个开源项目,是安卓端最火热的轻量级框架,由移动支付Square公司贡献(该公司还贡献了Picasso和LeakCanary) 。用于替代HttpUrlConnection和Apache HttpClient(android API23 里已移除HttpClient)。 okhttp有自己的官网,官网网址: OKHttp官网 如果想了解原码可以在github上下载,地址是: https://github.com/square/okhttp 在AndroidStudio中使用不需要下载jar包,直接添加依赖即可: compile ‘com.squareup.okhttp3:okhttp:3.4.1’ 在开发中我们会经常需要用到http请求,这里简单介绍一个http请求工具okHttp的用法 1、导入jar包 1 <dependency> 2 <groupId>com.squareup.okhttp3</groupId> 3 <artifactId>okhttp</artifactId> 4 <version>3.9.1</version> 5 </dependency> 2、为了便于以后使用,这里封装一个OkHttpUtil的工具类 get请求 1 /** 2 * get请求 3 * @param