如何删除 httr::GET 保留的 cookie?

Mic*_*hał 6 r httr

httr::GET 在向同一网站发出请求时保留 cookie。

  1. 是否可以查询那些保留的 cookie?
  2. 如何刷新那些保存的 cookie 并再次发出“原始”请求?

例子:

# Get login cookie
r1 <- GET("https://some.url/login", authenticate("foo", "bar"))

cookies(r1)
# returns a data frame of two cookies

# Make request that requires authentication cookie
# Only succeeds if r1 was made
r2 <- GET("https://some.url/data/?query&subset=1")
r2
Run Code Online (Sandbox Code Playgroud)

请注意,制作时r2您不必明确传递任何 cookie 信息,因为它们会自动存储在某处。

我想知道如何查询或删除这些存储的 cookie?

Tim*_*ce7 6

使用新句柄进行请求。

h1 <- handle('')
r1 <- GET("https://some.url/login", handle=h1, authenticate("foo", "bar"))

h2 <- handle('')
r2 <- GET("https://some.url/data/?query&subset=1", handle=h2)
Run Code Online (Sandbox Code Playgroud)