如何删除 httr::GET 保存的 cookies?
How to remove cookies preserved by httr::GET?
httr::GET
在向同一网站发出请求时保留 cookie。
- 是否可以查询那些保存的cookies?
- 如何清除那些保存的 cookie 并再次发出 "pristine" 请求?
示例:
# 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
请注意,在制作 r2
时,您不必显式传递任何 cookie 信息,因为它们会自动存储在某个地方。
我想知道如何查询或删除这些存储的cookies?
一个(非常迂回)方式是"reset"包:
detach("package:httr", unload=TRUE)
library(httr)
我还在寻找更好的东西。
使用新句柄请求。
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)
这对我有用:
# Get login cookie
r1 <- GET("https://some.url/login", authenticate("foo", "bar"))
cookies(r1)
# The cookies should be there, then:
handle_reset("https://some.url")
cookies(r1)
#now the cookies should be removed
希望对你有帮助
httr::GET
在向同一网站发出请求时保留 cookie。
- 是否可以查询那些保存的cookies?
- 如何清除那些保存的 cookie 并再次发出 "pristine" 请求?
示例:
# 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
请注意,在制作 r2
时,您不必显式传递任何 cookie 信息,因为它们会自动存储在某个地方。
我想知道如何查询或删除这些存储的cookies?
一个(非常迂回)方式是"reset"包:
detach("package:httr", unload=TRUE)
library(httr)
我还在寻找更好的东西。
使用新句柄请求。
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)
这对我有用:
# Get login cookie
r1 <- GET("https://some.url/login", authenticate("foo", "bar"))
cookies(r1)
# The cookies should be there, then:
handle_reset("https://some.url")
cookies(r1)
#now the cookies should be removed
希望对你有帮助