httr (version 0.2)

content: Extract content from a request.

Description

There are currently three ways to retrieve the contents of a request: as a raw object (as = "raw"), as a character vector, (as = "text"), and as parsed into an R object where possible, (as = "parsed"). If as is not specified, content does it's best to guess which output is most appropriate.

Usage

content(x, as = NULL, type = NULL, encoding = NULL, ...)

Arguments

x
request object
as
desired type of output: raw, text or parsed. content attempts to automatically figure out which one is most appropriate, based on the content-type.
type
MIME type (aka internet media type) used to override the content type returned by the server. See http://en.wikipedia.org/wiki/Internet_media_type for a list of common types.
encoding
For text, overrides the charset or the Latin1 (ISO-8859-1) default, if you know that the server is returning the incorrect encoding as the charset in the content-type. Use for text and auto outputs.
...
Other parameters parsed on to the parsing functions, if as = "auto"

Details

content currently knows about the following mime types: You can add new parsers by adding appropriately functions to httr:::parsers.

See Also

Other response methods: http_error, http_status, response, stop_for_status, url_ok, url_success, warn_for_status

Examples

Run this code
r <- POST("http://httpbin.org/post", body = list(a = 1, b = 2))
content(r) # automatically parses JSON
cat(content(r, "text"), "\n") # text content
content(r, "raw") # raw bytes from server

rlogo <- content(GET("http://cran.r-project.org/Rlogo.jpg"))
plot(0:1, 0:1, type = "n")
rasterImage(rlogo, 0, 0, 1, 1)

Run the code above in your browser using DataCamp Workspace