Question

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

Was it helpful?

Solution

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("; ")

 ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top