wt’s the different of using “request_get”, “request” and “get” provided
in net/http library?
Both of them can get the reponse.body
Citát Mento R. [email protected]:
wt’s the different of using “request_get”, “request” and “get” provided
in net/http library?
Both of them can get the reponse.body–
Posted via http://www.ruby-forum.com/.
Which get? I see both Net::HTTP::get, and Net::HTTP#get in the standard
documentation.
Also, it seems for #request you provide the request header yourself,
method,
HTTP version and all, for #request_get you only provide the URL.
David V.
There are really two “get” methods in Net::HTTP. But one is Class
method Net::HTTP::get, and the other is Instance method
Net::HTTP.get(Net::HTTP#get). So it is easy to differentiate these two
get methods. Then our goal should be to differentiate the following 3
methods.
- Net::HTTP#request_get
- Net::HTTP#request
- Net::HTTP#get
Net::HTTP#request_get means to send a GET request to the path
and get a response, as an HTTPResponse object. However Net::HTTP#request
means to send an HTTPRequest object REQUEST to the HTTP server. I.e.,
The HTTPRequest object of Net::HTTP#request might be either get/head
request or post/put request. This is the difference between it and
Net::HTTP#request_get.
Regarding Net::HTTP#get: In version 1.1 (ruby 1.6), it returns a
pair of objects, a Net::HTTPResponse object and the entity body string;
In version 1.2 (ruby 1.8), it returns a Net::HTTPResponse object. From
ruby 1.8, I think, Net::HTTP#get has very little difference with
Net::HTTP#request_get. The former method has a param named dest, which
Net::HTTP#request_get doesn’t have, as follows:
get(path, initheader = nil, dest = nil, &block)
Moreover, there’s been a method Net::HTTP#get2 that is
identical to Net::HTTP#request_get.
Regards,
Shiwei
(The views expressed are my own and not necessarily those of Oracle and
its affiliates.)