How to see my POST Request JSON payload in verification log? or literally anywhere?

I’m trying to see what the request payload being sent looks like in the verification log. I really just want to print all request and response payloads for every request but for some reason none of the methods I’ve tried are working.

I can get the response payload to print to the verification log using println(response.getResponseBodyContent()) but *println(request.getBodyContent()) doesn’t work at all. My verification log doesn’t show any errors or anything and it states that the print worked but it’s not printing the request payload.

import static org.assertj.core.api.Assertions.*
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.verification.WSResponseManager
import com.kms.katalon.core.util.KeywordUtil
import groovy.json.JsonSlurper
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent

RequestObject request = WSResponseManager.getInstance().getCurrentRequest()
println(request.getBodyContent())
ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()
println(response.getResponseBodyContent())
assert response.getStatusCode() == 200

Try removing the assert statement and putting in Verify… that might fix it. But others may have better solution.

@chase.small
I think its a bug to report, request.getBodyContent() does not work,
you can try request.httpBody.toString() , it will work though it is deprecated
I have previously reported this and still waiting a confirmation from KS.

Hi @chase.small,
getBodyContent() will return an instance of HttpBodyContent, on which you should call writeTo(...) passing in an argument of typeOutputStream to get the content of the body. You can refer to our Java Docs at https://docs.katalon.com/javadoc/index.html

1 Like

This workaround worked! I’m not sure how a deprecated method still works, but I’m glad it does! Thanks!

1 Like