httr (version 0.3)

add_headers: Add additional headers to a request.

Description

accept_json and accept_xml are useful shortcuts to request json or xml responses if the server supports content negotiation. json and xml are both easy to work with in R. See content for how to access the results as R objects.

Usage

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

accept_json()

accept_xml()

Arguments

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

Details

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

See Also

Other config: authenticate; config; set_cookies; timeout; use_proxy; user_agent; verbose

Examples

Run this code
add_headers(a = 1, b = 2)
add_headers(.headers = c(a = "1", b = "2"))

# Override default headers with empty strings
GET("http://had.co.nz", verbose())
GET("http://had.co.nz", c(verbose(), add_headers(Accept = "")))

GET("http://httpbin.org/headers")
GET("http://httpbin.org/headers",
 add_headers(version = version$version.string))

Run the code above in your browser using DataCamp Workspace