Wikipedia provides a useful list of common http headers: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields.

add_headers(..., .headers = character())

Arguments

...

named header values. To stop an existing header from being set, pass an empty string: "".

.headers

a named character vector

See also

accept() and content_type() for convenience functions for setting accept and content-type headers.

Other config: authenticate(), config(), set_cookies(), timeout(), use_proxy(), user_agent(), verbose()

Examples

add_headers(a = 1, b = 2)
#> <request> #> Headers: #> * a: 1 #> * b: 2
add_headers(.headers = c(a = "1", b = "2"))
#> <request> #> Headers: #> * a: 1 #> * b: 2
GET("http://httpbin.org/headers")
#> Response [http://httpbin.org/headers] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 284 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2", #> "X-Amzn-Trace-Id": "Root=1-5f3b0324-324a19d1faa8619291cc07a9" #> } #> }
# Add arbitrary headers GET( "http://httpbin.org/headers", add_headers(version = version$version.string) )
#> Response [http://httpbin.org/headers] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 332 B #> { #> "headers": { #> "Accept": "application/json, text/xml, application/xml, */*", #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2", #> "Version": "R version 3.6.2 (2019-12-12)", #> "X-Amzn-Trace-Id": "Root=1-5f3b0324-675c7e882f1d2a48d60cc3cf" #> } #> }
# Override default headers with empty strings GET("http://httpbin.org/headers", add_headers(Accept = ""))
#> Response [http://httpbin.org/headers] #> Date: 2020-08-17 22:22 #> Status: 200 #> Content-Type: application/json #> Size: 217 B #> { #> "headers": { #> "Accept-Encoding": "deflate, gzip", #> "Host": "httpbin.org", #> "User-Agent": "libcurl/7.58.0 r-curl/4.3 httr/1.4.2", #> "X-Amzn-Trace-Id": "Root=1-5f3b0324-f43798c8aa0541b831165086" #> } #> }