`
m635674608
  • 浏览: 5003718 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

OKHttp使用简介

 
阅读更多

现在Android网络方面的第三方库很多,volley,Retrofit,OKHttp等,各有各自的特点,这边博客就来简单介绍下如何使用OKHttp。

梗概

OKHttp是一款高效的HTTP客户端,支持连接同一地址的链接共享同一个socket,通过连接池来减小响应延迟,还有透明的GZIP压缩,请求缓存等优势 OKHttp官网

配置环境

支持Android 2.3及其以上版本,要求java JDK1.7以上

jar包引入

可以通过下载jar包直接导入工程地址如下下载地址
或者通过构建的方式导入
MAVEN:

<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp</artifactId>
  <version>2.4.0</version>
</dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

GRADLE

compile 'com.squareup.okhttp:okhttp:2.4.0'
  • 1
  • 1

用法

在向网络发起请求的时候,我们最常用的就是GET和POST,下面就来看看如何使用
1. GET
在OKHttp,每次网络请求就是一个Request,我们在Request里填写我们需要的url,header等其他参数,再通过Request构造出Call,Call内部去请求参数,得到回复,并将结果告诉调用者。

package com.jackchan.test.okhttptest;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import com.squareup.okhttp.Cache;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.File;
import java.io.IOException;


public class TestActivity extends ActionBarActivity {

    private final static String TAG = "TestActivity";

    private final OkHttpClient client = new OkHttpClient();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    execute();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public void execute() throws Exception {
        Request request = new Request.Builder()
                .url("http://publicobject.com/helloworld.txt")
                .build();
        Response response = client.newCall(request).execute();
        if(response.isSuccessful()){
            System.out.println(response.code());
            System.out.println(response.body().string());
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

我们通过Request.Builder传入url,然后直接execute执行得到Response,通过Response可以得到code,message等信息。

这个是通过同步的方式去操作网络请求,而android本身是不允许在UI线程做网络请求操作的,因此我们需要自己开启一个线程。

当然,OKHttp也支持异步线程并且有回调返回,有了上面同步的基础,异步只要稍加改动即可

private void enqueue(){
        Request request = new Request.Builder()
                .url("http://publicobject.com/helloworld.txt")
                .build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {

            }

            @Override
            public void onResponse(Response response) throws IOException {
                //NOT UI Thread
                if(response.isSuccessful()){
                    System.out.println(response.code());
                    System.out.println(response.body().string());
                }
            }
        });
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

就是在同步的基础上讲execute改成enqueue,并且传入回调接口,但接口回调回来的代码是在非UI线程的,因此如果有更新UI的操作记得用Handler或者其他方式。

2、POST

说完GET该介绍些如何使用POST,POST情况下我们一般需要传入参数,甚至一些header,传入参数或者header
比如传入header
Request request = new Request.Builder()
.url("https://api.github.com/repos/square/okhttp/issues")
.header("User-Agent", "OkHttp Headers.java")
.addHeader("Accept", "application/json; q=0.5")
.addHeader("Accept", "application/vnd.github.v3+json")
.build();

传入POST参数

RequestBody formBody = new FormEncodingBuilder()
    .add("platform", "android")
    .add("name", "bug")
    .add("subject", "XXXXXXXXXXXXXXX")
    .build();

    Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

可以看出来,传入header或者post参数都是传到Request里面,因此最后的调用方式也和GET方式一样

Response response = client.newCall(request).execute();
    if (response.isSuccessful()) {
        return response.body().string();
    } else {
        throw new IOException("Unexpected code " + response);
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

这个代码是同步网络请求,异步就改成enqueue就行了。

请求缓存

在网络请求中,缓存技术是一项应用比较广泛的技术,需要对请求过的网络资源进行缓存,而okhttp也支持这一技术,也使用十分方便,前文涨经常出现的OkHttpclient这个时候就要派送用场了。看下面代码

package com.jackchan.test.okhttptest;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import com.squareup.okhttp.Cache;
import com.squareup.okhttp.CacheControl;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

import java.io.File;
import java.io.IOException;


public class TestActivity extends ActionBarActivity {

    private final static String TAG = "TestActivity";

    private final OkHttpClient client = new OkHttpClient();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        File sdcache = getExternalCacheDir();
        int cacheSize = 10 * 1024 * 1024; // 10 MiB
        client.setCache(new Cache(sdcache.getAbsoluteFile(), cacheSize));
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    execute();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    public void execute() throws Exception {
        Request request = new Request.Builder()
                .url("http://publicobject.com/helloworld.txt")
                .build();

        Response response1 = client.newCall(request).execute();
        if (!response1.isSuccessful()) throw new IOException("Unexpected code " + response1);

        String response1Body = response1.body().string();
        System.out.println("Response 1 response:          " + response1);
        System.out.println("Response 1 cache response:    " + response1.cacheResponse());
        System.out.println("Response 1 network response:  " + response1.networkResponse());

        Response response2 = client.newCall(request).execute();
        if (!response2.isSuccessful()) throw new IOException("Unexpected code " + response2);

        String response2Body = response2.body().string();
        System.out.println("Response 2 response:          " + response2);
        System.out.println("Response 2 cache response:    " + response2.cacheResponse());
        System.out.println("Response 2 network response:  " + response2.networkResponse());

        System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68

okhttpclient有点像Application的概念,统筹着整个okhttp的大功能,通过它设置缓存目录,我们执行上面的代码,得到的结果如下
执行结果
response1 的结果在networkresponse,代表是从网络请求加载过来的,而response2的networkresponse 就为null,而cacheresponse有数据,因为我设置了缓存因此第二次请求时发现缓存里有就不再去走网络请求了。
但有时候即使在有缓存的情况下我们依然需要去后台请求最新的资源(比如资源更新了)这个时候可以使用强制走网络来要求必须请求网络数据

 public void execute() throws Exception {
        Request request = new Request.Builder()
                .url("http://publicobject.com/helloworld.txt")
                .build();

        Response response1 = client.newCall(request).execute();
        if (!response1.isSuccessful()) throw new IOException("Unexpected code " + response1);

        String response1Body = response1.body().string();
        System.out.println("Response 1 response:          " + response1);
        System.out.println("Response 1 cache response:    " + response1.cacheResponse());
        System.out.println("Response 1 network response:  " + response1.networkResponse());

        request = request.newBuilder().cacheControl(CacheControl.FORCE_NETWORK).build();
        Response response2 = client.newCall(request).execute();
        if (!response2.isSuccessful()) throw new IOException("Unexpected code " + response2);

        String response2Body = response2.body().string();
        System.out.println("Response 2 response:          " + response2);
        System.out.println("Response 2 cache response:    " + response2.cacheResponse());
        System.out.println("Response 2 network response:  " + response2.networkResponse());

        System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

上面的代码中
response2对应的request变成

request = request.newBuilder().cacheControl(CacheControl.FORCE_NETWORK).build();
  • 1
  • 1

我们看看运行结果
执行结果
response2的cache response为null,network response依然有数据。

同样的我们可以使用 FORCE_CACHE 强制只要使用缓存的数据,但如果请求必须从网络获取才有数据,但又使用了FORCE_CACHE 策略就会返回504错误,代码如下,我们去okhttpclient的缓存,并设置request为FORCE_CACHE

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        File sdcache = getExternalCacheDir();
        int cacheSize = 10 * 1024 * 1024; // 10 MiB
        //client.setCache(new Cache(sdcache.getAbsoluteFile(), cacheSize));
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    execute();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println(e.getMessage().toString());
                }
            }
        }).start();
    }

    public void execute() throws Exception {
        Request request = new Request.Builder()
                .url("http://publicobject.com/helloworld.txt")
                .build();

        Response response1 = client.newCall(request).execute();
        if (!response1.isSuccessful()) throw new IOException("Unexpected code " + response1);

        String response1Body = response1.body().string();
        System.out.println("Response 1 response:          " + response1);
        System.out.println("Response 1 cache response:    " + response1.cacheResponse());
        System.out.println("Response 1 network response:  " + response1.networkResponse());

        request = request.newBuilder().cacheControl(CacheControl.FORCE_CACHE).build();
        Response response2 = client.newCall(request).execute();
        if (!response2.isSuccessful()) throw new IOException("Unexpected code " + response2);

        String response2Body = response2.body().string();
        System.out.println("Response 2 response:          " + response2);
        System.out.println("Response 2 cache response:    " + response2.cacheResponse());
        System.out.println("Response 2 network response:  " + response2.networkResponse());

        System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

这里写图片描述

取消操作

网络操作中,经常会使用到对请求的cancel操作,okhttp的也提供了这方面的接口,call的cancel操作。使用 Call.cancel()可以立即停止掉一个正在执行的call。如果一个线程正在写请求或者读响应,将会引发IOException,同时可以通过 Request.Builder.tag(Object tag)给请求设置一个标签,并使用OkHttpClient.cancel(Object tag)来取消所有带有这个tag的call。但如果该请求已经在做读写操作的时候,cancel是无法成功的,会抛出IOException异常。

public void canceltest() throws Exception {
        Request request = new Request.Builder()
                .url("http://httpbin.org/delay/2") // This URL is served with a 2 second delay.
                .build();

        final long startNanos = System.nanoTime();
        final Call call = client.newCall(request);

        // Schedule a job to cancel the call in 1 second.
        executor.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.printf("%.2f Canceling call.%n", (System.nanoTime() - startNanos) / 1e9f);
                call.cancel();
                System.out.printf("%.2f Canceled call.%n", (System.nanoTime() - startNanos) / 1e9f);
            }
        }, 1, TimeUnit.SECONDS);

        try {
            System.out.printf("%.2f Executing call.%n", (System.nanoTime() - startNanos) / 1e9f);
            Response response = call.execute();
            System.out.printf("call is cancel:" + call.isCanceled() + "%n");
            System.out.printf("%.2f Call was expected to fail, but completed: %s%n",
                    (System.nanoTime() - startNanos) / 1e9f, response);
        } catch (IOException e) {
            System.out.printf("%.2f Call failed as expected: %s%n",
                    (System.nanoTime() - startNanos) / 1e9f, e);
        }
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

成功取消
这里写图片描述

取消失败

这里写图片描述

简单的对于OKHttp的使用就介绍到这里,下次将重点从源码角度介绍整个OKHttp是如何运转的。

上面部分的代码,我已经上传到github,各位看官有需要可以自行去下载源码下载

 

http://blog.csdn.net/chenzujie/article/details/46994073

分享到:
评论

相关推荐

    okhttp使用教程,通过okhttp将数据显示到textView上

    一、OkHttp简介 OkHttp是Android平台上广泛使用的网络库,它优化了网络通信过程,减少了TCP连接的创建和销毁,提高了请求速度。OkHttp支持HTTP/1.1和HTTP/2协议,具备缓存机制,可以处理重定向和自动处理gzip压缩,...

    OKHttp的使用Demo

    **OKHttp简介** OKHttp是Square公司开源的一款高效、易用的HTTP客户端库,它旨在通过减少网络延迟和减少内存消耗来改善Android和Java应用程序的性能。OKHttp提供了丰富的特性,如连接池、HTTP/2支持、透明GZIP压缩...

    OKHttp的使用demo

    **OKHttp简介** OKHttp是Square公司开发的一款高效、易用的网络请求库,广泛应用于Android应用开发中。它提供了一种简洁的API,使得开发者能够方便地发起HTTP请求,并处理响应。相比于Android自带的...

    OKHttp3的使用demo

    **OKHttp3简介** OKHttp 是一个高效的 HTTP 客户端,由 Square 公司开发并维护。OKHttp3 是其第三个主要版本,提供了一种简单、高效的接口来处理网络请求,尤其在Android平台上表现优秀。它通过减少网络通信中的...

    OkHttp使用示例

    一、OkHttp简介 OkHttp的设计目标是降低网络请求的延迟,提高数据传输效率,并且提供易于使用的API。它通过连接池、HTTP/2多路复用以及响应缓存等特性实现了这一目标。相比标准的HttpURLConnection,OkHttp在速度和...

    okhttp3简单封装使用

    ### 一、OkHttp简介 OkHttp是由Square公司开发的一款网络通信库,它提供了比Android默认HttpURLConnection更高效、更方便的网络请求方式。OkHttp的核心特点包括: 1. **缓存机制**:OkHttp支持自动缓存响应数据,...

    OKHttp.jar包

    **OKHttp简介** OKHttp是由Square公司开发的一款开源HTTP客户端,其设计目标是减少网络延迟,提高网络通信的效率。相比Android原生的HttpURLConnection,OKHttp提供了更好的性能和更低的资源消耗。OKHttp支持...

    OKHttp.jar包 3.4.1 下载

    ### OKHttp简介 OKHttp是一个开源HTTP客户端库,它的设计目标是使网络通信变得更加简单、快速且有效。与Android自带的HttpURLConnection相比,OKHttp提供了更好的性能和更低的资源消耗。它支持HTTP/1.1和HTTP/2协议...

    OkHttp基本使用教程(安卓端http请求框架)

    android网络请求框架之OkHttp,一个处理网络请求的开源项目,是安卓端最火热的轻量级框架,用于替代HttpUrlConnection和Apache HttpClient(android API23 6.0里已移除HttpClient,但仍可引入Jar包使用)。 OkHttp是一个...

    OkHttp的使用

    **OkHttp简介** OkHttp是Square公司开发的一款高效、易用的网络通信库,广泛应用于Android和Java项目中。它以其强大的性能、低资源消耗和丰富的功能特性在开发者社区中备受推崇。OkHttp的设计目标是简化HTTP请求,...

    okhttp多文件上传

    一、OkHttp简介 OkHttp是由Square公司开发的一个HTTP客户端库,它提供了一个简单、高效且强大的接口来处理网络请求。OkHttp通过缓存响应、连接池和线程安全的架构,显著提高了网络请求的速度和效率。 二、多文件...

    okhttp3源码运行

    OkHttp3是Android平台上广泛使用的网络通信库,它以其高效、稳定和易用性深受开发者喜爱。在本文中,我们将深入探讨OkHttp3的源码,理解其背后的运行机制,帮助开发者更好地理解和优化网络请求。 一、OkHttp3简介 ...

    OkHttp3.0 Demo

    **OkHttp3.0简介** OkHttp是Square公司推出的一款高效、现代的HTTP客户端库,其版本3.0带来了许多优化和新特性。OkHttp3.0致力于提供快速、稳定和低耗能的网络通信解决方案,它通过复用TCP连接、缓存响应以及高效的...

    okhttp-3.0.1.jar

    一、OkHttp简介 OkHttp以其高性能、低内存消耗和优秀的网络通信能力著称。它通过复用TCP连接、优化HTTP/2协议支持以及内置缓存机制,显著提升了网络请求的效率。在OkHttp 3.0.1版本中,对之前的版本进行了多项改进...

    OKHttp+Rxjava架包,okhttp.jar,,okio.jar,rxjava-1.2.4.jar

    标题中的"OKHttp+Rxjava"表明这是一个关于网络请求库OKHttp与反应式编程库RxJava的集成使用。OKHttp是一个高效的HTTP客户端,而RxJava则是一个用于处理异步操作和事件驱动编程的库。这两个组件结合在一起,可以提供...

    封装的okhttp demo

    **一、OkHttp简介** OkHttp是由Square公司开发的一款HTTP客户端,它通过一系列优化,如连接池、HTTP/2协议支持以及响应缓存,提供了快速、稳定且低耗能的网络通信能力。OkHttp的优势在于其简洁的API设计,能够方便...

    使用OKhttp,Rxjava封装的mvp模式架构

    **OKHttp简介:** OKHttp是Square公司开发的一款高效的HTTP客户端库,它具有以下特点: 1. **缓存机制**:支持自动缓存响应数据,减少网络请求。 2. **连接池**:复用TCP连接,减少建立连接的时间。 3. **异步请求**...

    封装好的OKHTTP

    **OKHTTP简介** OKHTTP是Java编程语言中广泛使用的HTTP客户端库,由Square公司开发。它以其高效、灵活和易用性而闻名,为开发者提供了简单的方法来执行HTTP请求并处理响应。OKHTTP的设计目标是减少网络延迟,提高...

    Android okhttp3.0忽略https证书的方法

    一、HTTPS 证书简介 HTTPS 证书是用于确保网络通信安全的一种数字证书。它可以验证服务器的身份,确保客户端和服务器之间的通信安全。 HTTPS 证书可以分为两种:一种是花钱购买的证书,这种证书可以被移动端直接...

    Android okhttp 网络框架 拿来就用

    一、OkHttp简介 OkHttp是由Square公司开发的一款高性能HTTP客户端库,它的设计目标是减少网络通信中的延迟,提高应用程序的响应速度。OkHttp通过连接池、缓存机制以及高效的协议处理,显著提升了网络请求的性能。 ...

Global site tag (gtag.js) - Google Analytics