Search code examples
androidandroid-studioretrofit2logcatokhttp

How copy request body, headers (without tags) from log cat in android studio when using Retrofit(Okhttp)?


I am unable to copy only request body (without tags) from log cat. I think it is very useful feature, because you often need to check request via postman, and it is hard making another similar request(especially if request is signed digitally). Here is log example which i want to copy without D: prefix:

D: --> POST http://url
D: Content-Type: application/xml; charset=utf-8
D: Content-Length: 3586
D: <?xml version="1.0" encoding="UTF-8"?><APRequest>
D: <jsonString>{"searchDate":"24.01.2019","userOrgCode":"19710003","userId":"5000000000014720"}</jsonString>
D: <dateOfSend>1548316774835</dateOfSend>
D: <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
D: <ds:SignedInfo>
D: <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
D: <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
D: <ds:Reference URI="">
D: <ds:Transforms>
D: <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
D: <ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/>
D: </ds:Transforms>
D: <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
D: <ds:DigestValue>KK5lQsy9CqracgR1YS2nZBkY2gU4ntOCtAgbPQeI7AU=</ds:DigestValue>
D: </ds:Reference>
D: </ds:SignedInfo>
D: <ds:SignatureValue>
D: T1CWxz0kgoKKFFwCBaA+oOfMunnzjF4fZEWoB5ll+Sdm6ql/mcHtJUEcVVF2MgwzYVP9O0TI5iiD
D: VGg9in36dC6WcCqb9UmNJM/I8KM1CDszwAWHLSto7dgSlE1DgXlImI2DhexcrXQyMyXVboQOPrHO
D: qbtT1Ou8hL+M8j/jxe5HMyANH55/3x83/8aae5GBxAVsaCyfJR5wWe4FXdDBRHU65RFe/JxRrDo3
D: 3sqed8P0AMtDPJwqKv3gm7y4i5sPpoRpaMTPBhKKqkZyFLT7TCVEoTb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5z2elqzgnT19wE8rUC7Q+lsX/xikKkBGweAZT4wYShB5x8opCnRfL
D: sLlo1Rs0VRN16U9EmcgWy4mP5o+QuHWAJyUiYy69WumTjQyvz5ss/vJoLsqzPl0s8uW5bQkg2OXC
D: O/MFXxnc1k7n81RzRbNx+AIn8B8f8W6qfOZ3ighgSw8hweIvtMjtN9xKYY+DRH781QeSVFfb3uUg
D: VEByOAuXc1U+F/v6TFh5DEZZaVRQrIT6OFAf2RHRVlJognrtVyK+7Dr3C0Hi
D: </ds:X509Certificate>
D: </ds:X509Data>
D: </ds:KeyInfo>
D: </ds:Signature></APRequest>
D: --> END POST (3586-byte body)
D: <-- 200 OK http://url (259ms)

Is it possible now copy logs without tags like D:, I:? Or is it possible print logs in single line when using retrofit with okhttp3?


Solution

  • There are a lot 3rd party lib for analysing (Intercepting) network request

    if using okhttp as base

    1. stetho
    2. chuck
    3. okhttp-logging-interceptor
    4. LoggingInterceptor

    in your case you can use this LoggingInterceptor