【问题标题】:Are the cookies not passed in the request header (in R)?cookie 是否未在请求标头中传递(在 R 中)?
【发布时间】:2020-03-19 02:15:09
【问题描述】:

编辑:

文档中的示例:

r <- GET("http://httpbin.org/cookies", set_cookies(a = 1, b = 2))

我希望 Cookie 成为请求标头:

r$request$headers
                                            Accept 
"application/json, text/xml, application/xml, */*"

加长版:

我在 R 中做了一个获取请求:

library(httr)
library(magrittr)
url <- "https://www.r-bloggers.com"
r <- url %>% GET 

并收集正在使用的 cookie:

ck <- cookies(r)$value
names(ck) <- cookies(r)$name

接下来我设置 cookie:

#url <- "https://www.r-bloggers.com" same page or
url <- "https://www.r-bloggers.com/econometrics-postdoc-and-computational-statistics-postdoc-openings-here-in-the-stan-group-at-columbia/"
req <- url %>% GET(set_cookies(.cookies = ck))

然后我希望我发送带有标题的 cookie。

req$request$headers

我希望 cookie 在请求标头中,因为:How are cookies passed in the HTTP protocol?。 我假设这些是我的请求标头req$request$headers

【问题讨论】:

    标签: r cookies get


    【解决方案1】:

    在 Github 上发布了一个答案:https://github.com/r-lib/httr/issues/629#issuecomment-557802675

    Cookie 已发送,只是在 request$headers 变量中看不到:

    r <- GET("https://httpbin.org/cookies", set_cookies(a = 1, b = 2))
    content(r)
    

    编辑:

    来自 GitHub 上 jennybc 的回答:

    with_verbose(GET(url = "https://www.r-bloggers.com", set_cookies(.cookies = c(a = "1"))))
    

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多