2011-03-16 10 views
5

grails के लिए बाकी ग्राहक प्लगइन का नवीनतम संस्करण:Grails बाकी ग्राहक प्लगइन - निर्दिष्ट करें हैडर डाटा

withHttp(uri: "http://foo/bar") { 
    def bodyContent = [ 
      apiKey: "somekey", 
      identifier: identity.identity, 
      activity: ac as JSON 
     ] 
    def json = post(path: 'activity', body: bodyContent) 
    if (json.stat == 'ok') { 
     wsr.success = true 
    } 
} 

मैं कैसे इस अनुरोध के हैडर डेटा जोड़ने करते हैं?

उत्तर

8

आपको पोस्ट विधि पर क्लोजर पास करने और शीर्षलेख सेट करने में सक्षम होना चाहिए।

withHttp(uri: "http://foo/bar") { 
    def bodyContent = [ 
      apiKey: "somekey", 
      identifier: identity.identity, 
      activity: ac as JSON 
     ] 
    def json = post(path: 'activity', body: bodyContent) { 
     headers.'User-Agent' = 'Mozilla/5.0 Ubuntu/8.10 Firefox/3.0.4' 
    } 
    if (json.stat == 'ok') { 
     wsr.success = true 
    } 
} 

निम्नलिखित भी काम करना चाहिए:

.... 
.... 
def json = post(path: 'activity', 
       body: bodyContent, 
       headers:['User-Agent':'myagent']) 
.... 
.... 
+0

मुझे यकीन है तुम सही हो। मैं इसका परीक्षण करूंगा और सुनिश्चित करूँगा। धन्यवाद। – Gregg

संबंधित मुद्दे