忽略Groovy HTTPBuilder中的cookie

时间:2014-10-28 20:48:50

标签: grails groovy httpbuilder

我在不需要Cookie的REST客户端调用中收到很多这些警告消息:

[http-bio-8080-exec-10] WARN  protocol.ResponseProcessCookies  - Cookie rejected: "[version: 1][name: mzf_in][value: 990108][domain: .xxxx.com][path: /asdf][expiry: null]". Domain attribute ".xxxx.com" violates RFC 2109: host minus domain may not contain any dots
[http-bio-8080-exec-10] WARN  protocol.ResponseProcessCookies  - Cookie rejected: "[version: 0][name: mzf_dr][value: 0][domain: .xxxx.com][path: /asdf][expiry: Wed Dec 31 21:00:00 ART 1969]". Illegal path attribute "/asdf". Path of origin: "/xyz"

我想在我使用的Groovy HTTPBuilder调用中禁用cookie处理。谷歌搜索我发现应该有一种方法来设置策略忽略cookie" (http://lists.canoo.com/pipermail/webtest/2006q2/005902.html)在" httpclient params"中。尝试将其添加到我的Groovy / Grails代码但无法使其工作。没有在官方HTTPBuilder网站上找到与此相关的任何信息。 有人在Groovy / Grails HTTPBuilder中配置了IGNORE_COOKIES选项吗?有人可以提供更具体的例子吗?

1 个答案:

答案 0 :(得分:0)

前段时间我使用了以下代码:

import static org.apache.http.client.params.ClientPNames.COOKIE_POLICY
import static org.apache.http.client.params.CookiePolicy.IGNORE_COOKIES

def http = new AsyncHTTPBuilder(
   poolSize: conf.getInt('client.poolSize'),
   uri: conf.getString('client.url'),
   contentType: JSON
)
http.client.params.setParameter(COOKIE_POLICY, IGNORE_COOKIES)
http.client.params.setParameter('http.connection-manager.max-total', 50)
http.client.params.setParameter('http.connection-manager.max-per-host', 50);
http