2011-03-16 8 views
5

La última versión del plug-in de cliente REST para griales:Grails Plugin RESTO Cliente - Especificar Datos de cabecera

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 
    } 
} 

¿Cómo agrego datos de cabecera a esta petición?

Respuesta

8

Debería poder pasar un Cierre al método de publicación y establecer encabezados ahí.

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 
    } 
} 

El siguiente también funcionará:

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

apuesto a que tienes razón. Lo probaré y me aseguraré. Gracias. – Gregg

Cuestiones relacionadas