使用rest-client获取并清除cookie

时间:2014-12-30 06:24:16

标签: ruby cookies rest-client

我在下面提出请求时需要存储cookie值: -

http://www.google.com

并清除Cookie,然后通过发出新请求创建Cookie

实施例: -

我正在提出这个要求: -

http://www.google.com

示例cookie存储如下: -

Name:   AID
Content:    AJHaeXK3Vn1wJpwSo6hSbO9wWd_qlgczYqbEz-ushHQ
Domain: .google.com
Path:   /ads
Send for:   Any kind of connection
Accessible to script:   No (HttpOnly)
Created:    Wednesday, December 24, 2014 at 11:58:15 AM
Expires:    Wednesday, June 15, 2016 at 12:30:00 PM

我想通过使用rest-client获得上述细节。

我需要清除上面存储的cookie,然后发出新的请求。

1 个答案:

答案 0 :(得分:1)

从我看到的,你从其他客户那里得到的cookie并没有你发布的全部信息:

{"PREF"=>"ID%3Da7ef052f0ef59efe%3AFF%3D0%3ATM%3D1419955587%3ALM%3D1419955587%3AS%3D1ieKQTEkT506sNXV", "domain"=>".google.pt", "NID"=>"67%3DbC3Y1L2DMHd_ZgpbnUjECoIeeRfFZixAeELI7nuT3f7LDFotI5xmGEu-FqO8O4456f1tQAim_d5KvjrLRApFGEk3lhAE7JXM3aI0DS1q6Pgl_0ahoVM_SvaXHgEQLt_5"}

但要实现您想要的(清除cookie以发出新请求),您可以使用:

request = RestClient.get 'https://www.google.com'
request.cookies.clear