How can I debug my retrofit API call?

后端 未结 3 1643
南笙
南笙 2021-02-06 23:01

I\'m using retrofit to get some data from the Flickr api. The method I\'m making the call in looks like this:

public static List getImageIds(int si         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 23:36

    An OkHttp interceptor which logs HTTP request and response data.

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(Level.BASIC);
    OkHttpClient client = new OkHttpClient.Builder()
        .addInterceptor(logging)
        .build();
    

    You can change the log level at any time by calling setLevel.

    There are 4 levels: NONE, BASIC, HEADERS, BODY

    To log to a custom location, pass a Logger instance to the constructor.

    HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new 
    Logger() {
    @Override public void log(String message) {
        Log.d(TAG, "message: ");
        }
    });
    

    From Gradle

    compile 'com.squareup.okhttp3:logging-interceptor:(insert latest version)'
    

    Follow this reference

    EDITED: I also found this library which has a very nice structure and clean log. Try it!!

提交回复
热议问题