Home » Android » android – okhttp loggin interceptor in multipart

android – okhttp loggin interceptor in multipart

Posted by: admin May 14, 2020 Leave a comment


I am trying to upload an image using okHTTP multi part into a server. the server does not accept my request. my problem is that I cannot see the parts of my multi part in the logging intercepter, so I cannot debug. here is the code that I use and the reulting log cat and the desired payload. any help is appreciated.

            RequestBody requestBody = new MultipartBody.Builder()
                .addFormDataPart("uploaded_file", filename, RequestBody.create(MEDIA_TYPE_PNG, sourceFile))
                .addFormDataPart("flowChunkNumber", "1")
                .addFormDataPart("flowCurrentChunkSize", String.valueOf(sourceFile.getTotalSpace()))
                .addFormDataPart("flowChunkSize", "1048576")
                .addFormDataPart("flowIdentifier", "4731-images1jpeg")
                .addFormDataPart("flowFilename", "images (1).jpeg")
                .addFormDataPart("flowFilename", "images (1).jpeg")
                .addFormDataPart("flowRelativePath", "images (1).jpeg")
                .addFormDataPart("flowTotalChunks", "1")

        Request request = new Request.Builder()
                .addHeader("cookie", ******* )

        HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();

        OkHttpClient client = new OkHttpClient

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

and this is what I see in the log cat when I use an interceptor

D/OkHttp: –> POST https://www.appido.ir/api/profile/avatar http/1.1

D/OkHttp: Content-Type: multipart/form-data;

D/OkHttp: Content-Length: 14097
D/OkHttp: cookie: ************************
Domain=.appido.ir; expires=Tue, 23-Aug-2016 13:31:11 GMT; Path=/

D/OkHttp: Host: www.appido.ir

D/OkHttp: Connection: Keep-Alive

D/OkHttp: Accept-Encoding: gzip

D/OkHttp: User-Agent: okhttp/3.4.1

h������gTRC���������lumi���� 07-25 07:47:49.163
7776-8509/com.androidbuts.uploadimage D/OkHttp: |������meas���� 07-25
07:47:49.163 7776-8509/com.androidbuts.uploadimage D/OkHttp:
�������$bkpt���� 07-25 07:47:49.163
7776-8509/com.androidbuts.uploadimage D/OkHttp: �������rXYZ����

and this gibberish goes on for many lines

D/OkHttp: –> END POST (14097-byte body)

How can I see a meaningful log cat? I want to acihieve this :

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowChunkNumber”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowChunkSize”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowCurrentChunkSize”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowTotalSize”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowIdentifier”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowFilename”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowRelativePath”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”flowTotalChunks”

——WebKitFormBoundaryJDdhM3Si8enJZABA Content-Disposition: form-data; name=”file”; filename=”blob” Content-Type:


How to&Answers:

The way to see the contents of a Multipart upload from Okttp and Retrofit is to use Stetho, by Facebook, and add StethoInterceptor to the Okhttp logger


It puts the Android app’s network requests in your dev machine’s chrome inspector.


it seems to be a bug in the logging intercepter.

I was able to solve this issue buy debugging the logging intercepter.
the problem is the body for multi part is too big and the itercepter cannot display such a big body all at once. it needs to be printed line by line.
here is the modified version on logging intercepter that works with multi part in okhttp 3.4.1 :