-
Notifications
You must be signed in to change notification settings - Fork 326
Response Handling
Tony Arcieri edited this page Mar 7, 2016
·
15 revisions
When we make an HTTP request, we obtain an HTTP::Response
object:
>> response = HTTP.get('https://www.google.com')
=> #<HTTP/1.0 200 OK @headers={"Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Fri, ...>
There are several methods of interest we can call on the response (see also the YARD documentation):
-
#code: (returns
Fixnum
) the HTTP status code of the response -
#body: (returns
HTTP::Body
) an object representing the body. Can be used for streaming -
#to_s: (returns
String
) quickly obtain the response body as a string -
#cookies: (returns
HTTP::CookieJar
) a cookie jar containing all of the response cookies for a request