Search code examples
rhttr

How to remove cookies preserved by httr::GET?


httr::GET preserves cookies when making requests to the same website.

  1. Is it possible to query those preserved cookies?
  2. How can I flush those preserved cookies and make "pristine" requests again?

Example:

# 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

Notice that when making r2 you dont have to pass any cookie information explicitely as they are stored somewhere automatically.

I would like to know how these stored cookies can be queried or deleted?


Solution

  • Use a new handle to request.

    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)