views:

57

answers:

1

Dear All:

I am doing this (in Groovy):

def cookies=webClient.cookieManager.cookies
def http=new HTTPBuilder("myurl")
http.request(POST) {
   def headersCookie=''
   cookies.eachWithIndex() { cookie,i->
   if (i>0) {
       headersCookie+='; '
   }
   headersCookie+=cookie.getName()+"="+cookie.getValue()
 }
 headers.'Cookie'=headersCookie

 ...
}

Is there a better/less hacky way?

Thank you Misha

+2  A: 

Here's a groovier way of doing it:

def cookies=webClient.cookieManager.cookies
def http=new HTTPBuilder("myurl")
http.request(POST) {
 headers.'Cookie'=cookies.collect{it.name+"="+it.value}.join("; ")

 ...
}
ataylor
Dude you're awesome. I'm still learning this Groovy stuff ;)
Misha Koshelev