httr (version 0.2)

http_status: Give information on the status of a request.

Description

Extract the http status code and convert it into a human readable message.

Usage

http_status(x)

Arguments

x
a request object

Value

  • If the status code does not match a known status, the function errors out. Otherwise, it returns a list with components
  • categorythe broad category of the status
  • messagethe meaning of the status code

Details

http servers send a status code with the response to each request. This code gives information regarding the outcome of the execution of the request on the server. Roughly, codes in the 200s mean the request was successfully executed; codes in the 300s mean the page was redirected; codes in the 400s mean there was a mistake in the way the client sent the request; codes in the 500s mean the server failed to fulfill an apparently valid request. More details on the codes can be found at http://en.wikipedia.org/wiki/Http_error_codes.

See Also

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

Examples

Run this code
x <- GET("http://httpbin.org/status/200")
http_status(x)

http_status(GET("http://httpbin.org/status/300"))
http_status(GET("http://httpbin.org/status/301"))
http_status(GET("http://httpbin.org/status/404"))

# errors out on unknown status
http_status(GET("http://httpbin.org/status/320"))

Run the code above in your browser using DataLab