如何从HttpResponseDecorator获取原始响应和URL

zor*_*119 10 groovy httpresponse httpbuilder

REST客户端HTTP生成器返回HttpResponseDecorator.如何从中获取原始响应(用于记录目的)?

编辑(一些代码可能很方便):

    withRest(uri: domainName) {
        def response = post(path: 'wsPath', query: [q:'test'])
        if (!response.success) {
            log.error "API call failed. HTTP status: $response.status"
            // I want to log raw response and URL constructed here
        }
Run Code Online (Sandbox Code Playgroud)

小智 12

我一直在做同样问题的噩梦.这是我使用HTTPBuilder的解决方案: -

response.failure = {resp ->
    println "request failed with status ${resp.status}, response body was [${resp.entity.content.text}]"
    return null
}
Run Code Online (Sandbox Code Playgroud)

希望有所帮助!

  • 当我完成上述操作时,我得到了"java.io.IOException:尝试从封闭流中读取". (9认同)