2013-04-19 2 views
8

से कच्चे प्रतिक्रिया और यूआरएल को कैसे प्राप्त करें REST ClientHTTP BuilderHttpResponseDecorator देता है। मैं इसके बारे में कच्ची प्रतिक्रिया कैसे प्राप्त कर सकता हूं (लॉगिंग उद्देश्यों के लिए)?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 
     } 

उत्तर

8

मैं एक ही समस्या के साथ एक बुरा सपना हो रही किया गया है। HTTPBuilder का उपयोग करके मेरा समाधान यहां दिया गया है: -

response.failure = {resp -> 
    println "request failed with status ${resp.status}, response body was [${resp.entity.content.text}]" 
    return null 
} 

आशा है कि मदद करता है!

+8

जब मैं ऊपर, मुझे मिल किया था "java.io.IOException:। का प्रयास बंद स्ट्रीम से पढ़ने" –

-2

इस प्रयास करें:

println response.data

+0

http://javadox.com/org.codehaus.groovy.modules.http-builder/http-builder/0.6/groovyx/net/http/HttpResponseDecorator.html#getData() यह सचमुच कच्चे प्रतिक्रिया का सटीक विपरीत है। –