Reads the next expression from this printer.
See IO#gets
for more information.
Returns true
; retained for compatibility.
Sends a GET request and returns the HTTP response body as a string.
With string arguments hostname
and path
:
hostname = 'jsonplaceholder.typicode.com' path = '/todos/1' puts Net::HTTP.get(hostname, path)
Output:
{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }
With URI
object uri
and optional hash argument headers
:
uri = URI('https://jsonplaceholder.typicode.com/todos/1') headers = {'Content-type' => 'application/json; charset=UTF-8'} Net::HTTP.get(uri, headers)
Related:
Net::HTTP::Get
: request class for HTTP method GET
.
Net::HTTP#get
: convenience method for HTTP method GET
.
Sends a GET request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Get
object created from string path
and initial headers hash initheader
.
With a block given, calls the block with the response body:
http = Net::HTTP.new(hostname) http.get('/todos/1') do |res| p res end # => #<Net::HTTPOK 200 OK readbody=true>
Output:
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false\n}"
With no block given, simply returns the response object:
http.get('/') # => #<Net::HTTPOK 200 OK readbody=true>
Related:
Net::HTTP::Get
: request class for HTTP method GET.
Net::HTTP.get
: sends GET request, returns response body.
Sends a LOCK request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Lock
object created from string path
, string body
, and initial headers hash initheader
.
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.lock('/todos/1', data)
Sends an UNLOCK request to the server; returns an instance of a subclass of Net::HTTPResponse
.
The request is based on the Net::HTTP::Unlock
object created from string path
, string body
, and initial headers hash initheader
.
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}' http = Net::HTTP.new(hostname) http.unlock('/todos/1', data)
Pushes back erred argument(s) to argv
.
Default stringizing method to emit standard error message.
Register a listener for one or more events.
def register: (Listener, *Symbol) -> void
def operator: () -> String
def operator: () -> String
def closing: () -> String
?
def closing: () -> String
?
def operator: () -> String
?
def operator: () -> String
def operator: () -> String
def closing: () -> String
def operator: () -> String
def closing: () -> String
?