OkHttp in android for making network requests

前端 未结 8 1644
北海茫月
北海茫月 2020-12-29 08:18

What I am trying to do::

I am trying to learn the usage of Okhttp for making networking calls in android


What I have done

8条回答
  •  旧巷少年郎
    2020-12-29 09:00

    The method execute(Request) is undefined for the type OkHttpClient

    You are getting this exception because there is no such method ie.execute(Request) for OkHttpClient. Rather it is invoked on Call object which is obtained using OkHttpClient object as follows:

      Call call = client.newCall(request);
      Response response = call.execute();
    

    I think you should be using

    Response response = client.newCall(request).execute();
    

    instead of Response response = client.execute(request);

    OkHttp docs

    OkHttp Blog

提交回复
热议问题