Retrofit - 14 okHttpCall object and synchronous request & asynchronous request in retrofit

Important three lines of code

ServiceMethod<Object, Object> serviceMethod = (ServiceMethod<Object, Object>) loadServiceMethod(method);
OkHttpCall<Object> okHttpCall = new OkHttpCall<>(serviceMethod, args);
return serviceMethod.adapt(okHttpCall);

[retrofit synchronous request - OkHttpCall.execute( )]
ParameterHandler (step 1): It is still necessary to use our ParameterHandler to parse each parameter in our network request interface method.
ServiceMethod (step 2): According to the ServiceMethod object we created, use the request object required to create an OKHTTP request. ServiceMethod is very important, it contains all the parameters we need for network requests, so we can create Request objects through it. At the same time, the ServiceMethod that needs attention is cached, in order to make it more efficient when we get it.
Okhttp sends a network request (step 3): Get the OKHTTP Call that the request is given to us to send the actual network request.
converter (step 4): After sending, we need to receive the data returned by the server, and then use the data converter converter to convert the network response into a java object.

[retrofit asynchronous request — OkHttpCall.enqueue( ) ]






Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325907522&siteId=291194637