Environment Description:
Compile ' io.reactivex:rxandroid:1.1.0 '
compile ' io.reactivex:rxjava:1.1.0 '
compile ' Com.squareup.retrofit2:retrofit:2.0.0-beta4 '
compile ' com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4 '
compile ' com.squareup.okhttp3:logging-interceptor:3.2.0 '
Use Rxjava, rxandroid version 1.1.0
Using the Retrofit2 2.0.0-beta4 version
1, also need to increase OKHTTP3, and Okio dependence?
No, Retrofit2 has added Okhttp3,okio dependencies by default, so our project does not need to declare OKHTTP3, Okio dependencies.
2, how to increase debugging information.
Previous versions, there was a listener method on the retrofit object that could listen to retrofit and print some debug information, but in the BETA4 version there was no way to increase the monitoring, So you can only set up a interceptor on the OKHTTP3 to print some of the required logs.
Httplogginginterceptor logging = new Httplogginginterceptor ();
Set your desired log level
logging.setlevel (HttpLoggingInterceptor.Level.BODY);
Add your other interceptors
... Add logging as last Interceptor
okhttpclient client = new Okhttpclient.builder ()
. Addinterceptor (logging)
. Build ();
Retrofit RETROFIT = new Retrofit.builder ()
. BaseURL (base_url).
Client (client).
Addcalladapterfactory ( Rxjavacalladapterfactory.create ())
. Addconverterfactory (Fastjsonconverterfactory.create ())
. Build ();
3, print out the log, only send, no receipts, with the browser can see the return value.
03-09 09:11:34.609 13471-13491/com.xxxxxx.carcare d/okhttp: <--OK http://192.168.0.46:8080/users/ 56c2c40d77ce6f9a3c73a09e (2692ms)
03-09 09:11:34.639 13471-13491/com.xxxxxx.carcare d/okhttp: <--End HTTP (82 -byte body)
This is because, for Rx's sake, RX will default to thread scheduling. The default thread is the RX line Cheng Chili, and the network request needs to be placed in the IO thread, and the returned results need to be manipulated in the main thread.
Need to configure thread scheduling on observable
. Observeon (Androidschedulers.mainthread ())
. Subscribeon (Schedulers.io ())
4, using Fastjson as a serialization tool
See my other article.
http://blog.csdn.net/soslinken/article/details/50832958