开发者

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

 ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜