Results for: "strip"

Get the URI of the remote object.

Get the URI of the remote object.

No documentation available
No documentation available
No documentation available
No documentation available
No documentation available

Posts data to a host; returns a Net::HTTPResponse object.

Argument url must be a URL; argument data must be a string:

_uri = uri.dup
_uri.path = '/posts'
data = '{"title": "foo", "body": "bar", "userId": 1}'
headers = {'content-type': 'application/json'}
res = Net::HTTP.post(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true>
puts res.body

Output:

{
  "title": "foo",
  "body": "bar",
  "userId": 1,
  "id": 101
}

Related:

Creates a new Net::HTTP object, http, via Net::HTTP.new:

Net::HTTP.new(address, port, p_addr, p_port, p_user, p_pass)

Note: If port is nil and opts[:use_ssl] is a truthy value, the value passed to new is Net::HTTP.https_default_port, not port.

With no block given:

With a block given:

Example:

hostname = 'jsonplaceholder.typicode.com'
Net::HTTP.start(hostname) do |http|
  puts http.get('/todos/1').body
  puts http.get('/todos/2').body
end

Output:

{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}
{
  "userId": 1,
  "id": 2,
  "title": "quis ut nam facilis et officia qui",
  "completed": false
}

If the last argument given is a hash, it is the opts hash, where each key is a method or accessor to be called, and its value is the value to be set.

The keys may include:

Returns the IP address for the connection.

If the session has not been started, returns the value set by ipaddr=, or nil if it has not been set:

http = Net::HTTP.new(hostname)
http.ipaddr # => nil
http.ipaddr = '172.67.155.76'
http.ipaddr # => "172.67.155.76"

If the session has been started, returns the IP address from the socket:

http = Net::HTTP.new(hostname)
http.start
http.ipaddr # => "172.67.155.76"
http.finish

Sets the IP address for the connection:

http = Net::HTTP.new(hostname)
http.ipaddr # => nil
http.ipaddr = '172.67.155.76'
http.ipaddr # => "172.67.155.76"

The IP address may not be set if the session has been started.

Returns true if the HTTP session has been started.

Opens a TCP connection and HTTP session.

When this method is called with a block, it passes the Net::HTTP object to the block, and closes the TCP connection and HTTP session after the block has been executed.

When called with a block, it returns the return value of the block; otherwise, it returns self.

Posts data (must be a String) to path. header must be a Hash like { ‘Accept’ => ‘/’, … }.

This method returns a Net::HTTPResponse object.

If called with a block, yields each fragment of the entity body in turn as a string as it is read from the socket. Note that in this case, the returned response object will not contain a (meaningful) body.

dest argument is obsolete. It still works but you must not use it.

This method never raises exception.

response = http.post('/cgi-bin/search.rb', 'query=foo')

# using block
File.open('result.txt', 'w') {|f|
  http.post('/cgi-bin/search.rb', 'query=foo') do |str|
    f.write str
  end
}

You should set Content-Type: header field for POST. If no Content-Type: field given, this method uses “application/x-www-form-urlencoded” by default.

Sends a TRACE request to the path and gets a response, as an HTTPResponse object.

Sends an HTTPRequest object req to the HTTP server.

If req is a Net::HTTP::Post or Net::HTTP::Put request containing data, the data is also sent. Providing data for a Net::HTTP::Head or Net::HTTP::Get request results in an ArgumentError.

Returns an HTTPResponse object.

When called with a block, passes an HTTPResponse object to the block. The body of the response will not have been read yet; the block can process it using HTTPResponse#read_body, if desired.

This method never raises Net::* exceptions.

No documentation available
No documentation available
No documentation available

Description

Returns the authority for an HTTP uri, as defined in datatracker.ietf.org/doc/html/rfc3986/#section-3.2.

Example:

URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com"
URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000"
URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"

Description

Returns the origin for an HTTP uri, as defined in datatracker.ietf.org/doc/html/rfc6454.

Example:

URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').origin #=> "http://www.example.com"
URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').origin #=> "http://www.example.com:8000"
URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').origin #=> "http://www.example.com"
URI::HTTPS.build(host: 'www.example.com', path: '/foo/bar').origin #=> "https://www.example.com"

Produces the summary text. Each line of the summary is yielded to the block (without newline).

sdone

Already summarized short style options keyed hash.

ldone

Already summarized long style options keyed hash.

width

Width of left side (option part). In other words, the right side (description part) starts after width columns.

max

Maximum width of left side -> the options are filled within max columns.

indent

Prefix string indents all summarized lines.

Creates the summary table, passing each line to the block (without newline). The arguments args are passed along to the summarize method which is called on every option.

This is used as a predicate, and ought to be called first.

No documentation available
Search took: 3ms  ·  Total Results: 1534