resp_body_raw {httr2} | R Documentation |
resp_body_raw()
returns the raw bytes.
resp_body_string()
returns a UTF-8 string.
resp_body_json()
returns parsed JSON.
resp_body_html()
returns parsed HTML.
resp_body_xml()
returns parsed XML.
resp_body_json()
and resp_body_xml()
check that the content-type header
is correct; if the server returns an incorrect type you can suppress the
check with check_type = FALSE
.
resp_body_raw(resp)
resp_body_string(resp, encoding = NULL)
resp_body_json(resp, check_type = TRUE, simplifyVector = FALSE, ...)
resp_body_html(resp, check_type = TRUE, ...)
resp_body_xml(resp, check_type = TRUE, ...)
resp |
A response object. |
encoding |
Character encoding of the body text. If not specified, will use the encoding specified by the content-type, falling back to UTF-8 with a warning if it cannot be found. The resulting string is always re-encoded to UTF-8. |
check_type |
Check that response has expected content type? Set to
|
simplifyVector |
Should JSON arrays containing only primitives (i.e. booleans, numbers, and strings) be caused to atomic vectors? |
... |
Other arguments passed on to |
resp_body_raw()
returns a raw vector.
resp_body_string()
returns a string.
resp_body_json()
returns NULL, an atomic vector, or list.
resp_body_html()
and resp_body_xml()
return an xml2::xml_document
resp <- request("https://httr2.r-lib.org") %>% req_perform()
resp
resp %>% resp_body_raw()
resp %>% resp_body_string()
if (requireNamespace("xml2", quietly = TRUE)) {
resp %>% resp_body_html()
}