我们使用 HttpHead 从客户的网站获取信息,但由于某种原因,我们也在响应中获取 cookie。是预期的吗?有没有办法设置不返回cookie?
下面是我们的代码
HttpClient httpclient = new DefaultHttpClient();
// the time it takes to open TCP connection.
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, this.timeout);
// timeout when server does not send data.
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, this.timeout);
// the head method
HttpHead httphead = new HttpHead(url);
HttpResponse response = httpclient.execute(httphead);
我们收到以下警告,表明响应中也返回了 cookie。
[警告] ResponseProcessCookies - Cookie 被拒绝:“[版本:0][名称:DXFXFSG][值:AUR][域:...省略...][路径:/][过期:null]”。非法域属性“...省略...”。来源域:“...省略...”
最佳答案
是的,这是预期的;您应该得到与等效的 GET
相同的响应,只是没有正文。如果 GET
包含 cookie,您应该会看到它。
顺便说一句,我相信您从您提供的经过编辑的消息中看到的警告是,服务器正在尝试为不同的域设置 cookie。
关于java - 为什么要为 HttpHead 方法取回 cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13715339/