You can just try this:
url <- "http://httpbin.org/get"
httr::GET(url)
httr::GET(url, httr::add_headers(a = 1, b = 2))
httr::GET(url, httr::set_cookies(a = 1, b = 2))
httr::GET(url, httr::add_headers(a = 1, b = 2), httr::set_cookies(a = 1, b = 2))
httr::GET(url, httr::add_headers(a = 1, b = 2, cookie = 'c=3;d=4'), httr::set_cookies(a = 1, b = 2))
# codes ref by: https://httr.r-lib.org/reference/GET.html
And these will be the outs with commands:
httr::GET(url)
#| Response [http://httpbin.org/get]
#| Date: 2024-07-31 02:14
#| Status: 200
#| Content-Type: application/json
#| Size: 378 B
#| {
#| "args": {},
#| "headers": {
#| "Accept": "application/json, text/xml, application/xml, */*",
#| "Accept-Encoding": "deflate, gzip, br, zstd",
#| "Host": "httpbin.org",
#| "User-Agent": "libcurl/7.81.0 r-curl/5.2.1 httr/1.4.7",
#| "X-Amzn-Trace-Id": "Root=1-66a99dfc-3ee62d216a517e6844e8815f"
#| },
#| "origin": "101.200.73.219",
#| ...
httr::GET(url, httr::add_headers(a = 1, b = 2))
#| Response [http://httpbin.org/get]
#| Date: 2024-07-31 02:14
#| Status: 200
#| Content-Type: application/json
#| Size: 408 B
#| {
#| "args": {},
#| "headers": {
#| "A": "1",
#| "Accept": "application/json, text/xml, application/xml, */*",
#| "Accept-Encoding": "deflate, gzip, br, zstd",
#| "B": "2",
#| "Host": "httpbin.org",
#| "User-Agent": "libcurl/7.81.0 r-curl/5.2.1 httr/1.4.7",
#| "X-Amzn-Trace-Id": "Root=1-66a99dfc-2fddaa4e49a8325309990191"
#| ...
httr::GET(url, httr::set_cookies(a = 1, b = 2))
#| Response [http://httpbin.org/get]
#| Date: 2024-07-31 02:14
#| Status: 200
#| Content-Type: application/json
#| Size: 404 B
#| {
#| "args": {},
#| "headers": {
#| "Accept": "application/json, text/xml, application/xml, */*",
#| "Accept-Encoding": "deflate, gzip, br, zstd",
#| "Cookie": "a=1;b=2",
#| "Host": "httpbin.org",
#| "User-Agent": "libcurl/7.81.0 r-curl/5.2.1 httr/1.4.7",
#| "X-Amzn-Trace-Id": "Root=1-66a99dfc-44b9d09700c6b7f87e086e40"
#| },
#| ...
httr::GET(url, httr::add_headers(a = 1, b = 2), httr::set_cookies(a = 1, b = 2))
#| Response [http://httpbin.org/get]
#| Date: 2024-07-31 02:14
#| Status: 200
#| Content-Type: application/json
#| Size: 434 B
#| {
#| "args": {},
#| "headers": {
#| "A": "1",
#| "Accept": "application/json, text/xml, application/xml, */*",
#| "Accept-Encoding": "deflate, gzip, br, zstd",
#| "B": "2",
#| "Cookie": "a=1;b=2",
#| "Host": "httpbin.org",
#| "User-Agent": "libcurl/7.81.0 r-curl/5.2.1 httr/1.4.7",
#| ...
httr::GET(url, httr::add_headers(a = 1, b = 2, cookie = 'c=3;d=4'), httr::set_cookies(a = 1, b = 2))
#| Response [http://httpbin.org/get]
#| Date: 2024-07-31 02:14
#| Status: 200
#| Content-Type: application/json
#| Size: 434 B
#| {
#| "args": {},
#| "headers": {
#| "A": "1",
#| "Accept": "application/json, text/xml, application/xml, */*",
#| "Accept-Encoding": "deflate, gzip, br, zstd",
#| "B": "2",
#| "Cookie": "c=3;d=4",
#| "Host": "httpbin.org",
#| "User-Agent": "libcurl/7.81.0 r-curl/5.2.1 httr/1.4.7",
#| ...
So, the httr::set_cookies
is like a warp to httr::add_headers
, but the httr::add_headers
have bigger priority while they both appears to setting cookies.
But, httr::set_cookies(...)
is friendly to read rather than httr::add_headers(cookie = ....)
, so I think you can still just use it.