Convert cookies from HTMLUnit to HTTPBuilder?
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()
}
he开发者_JS百科aders.'Cookie'=headersCookie
...
}
Is there a better/less hacky way?
Thank you Misha
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("; ")
...
}
精彩评论