开发者

Convert cookies from HTMLUnit to HTTPBuilder?

开发者 https://www.devze.com 2023-01-02 15:11 出处:网络
I am doing this (in Groovy): def cookies=webClient.cookieManager.cookies def http=new HTTPBuilder(\"myurl\")

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

精彩评论

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