【问题标题】:Retrofit taking too long for DNS resolution改造 DNS 解析耗时过长
【发布时间】:2019-06-18 09:56:35
【问题描述】:

我正在使用改造来调用“https://google.com”。第一个请求花费的时间太长。

我尝试在网上搜索以找到解决方案,但我无法找到任何解决方案。

下面是sn-p的代码:

    String baseURL1 = "https://google.com";
    OkHttpClient httpClient = new OkHttpClient.Builder()
                .eventListener(new PrintingEventListener())
                .build();
    Retrofit client = new Retrofit.Builder().baseUrl(baseURL1).client(httpClient)
            .build();
    TestInterface testInterface = client.create(TestInterface.class);
    Call<ResponseBody> testCall = testInterface.testCall();

    System.out.println("Scanning REQUEST 1 (new connection)");
    testCall.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.i( TAG, "Scanning apiCall end success");
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.i( TAG, "Scanning apiCall end failed");
        }});

我正在使用最新版本的改造:

implementation 'com.squareup.retrofit2:retrofit:2.6.0'

带有 EventListener 的日志语句:

REQUEST 1 (new connection)
0.000 callStart
0.007 dnsStart
5.048 dnsEnd
5.049 connectStart
5.056 secureConnectStart
5.106 secureConnectEnd
5.108 connectEnd
5.109 connectionAcquired
5.110 requestHeadersStart
5.112 requestHeadersEnd
5.196 responseHeadersEnd
5.197 responseBodyStart
REQUEST 1 (new connection) end success

非常感谢任何帮助。

【问题讨论】:

    标签: android https dns retrofit2


    【解决方案1】:

    您需要检查运行上述代码的设备使用的 Internet 连接和 DNS 服务器。 尝试使用另一个 DNS 解析器客户端运行 google.com 的 dns 解析,看看这是否真的是改造的问题。我猜它不是在改造级别,而是在您的网络级别。

    【讨论】:

    • 我能够通过使用谷歌的公共 dns 解析器来解决这个问题,如 here 所述。
    猜你喜欢
    • 2013-06-16
    • 2013-02-26
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    相关资源
    最近更新 更多