Module: Baidu::Support::Request
- Includes:
- Baidu::Support
- Included in:
- OAuth::Client, OAuth::RESTClient, PCS::Client
- Defined in:
- lib/baidu/support/request.rb
Constant Summary collapse
- MAX_REDIRECT_LIMIT =
最多重定向次数
10
Instance Method Summary collapse
-
#get(path, query = {}, options = {}) {|segment| ... } ⇒ Object
发送 GET 请求.
-
#post(path, query = {}, body = {}, options = {}) ⇒ Object
发送 POST 请求.
Instance Method Details
#get(path, query = {}, options = {}) {|segment| ... } ⇒ Object
发送 GET 请求
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/baidu/support/request.rb', line 19 def get(path, query={}, ={}, &block) url = build_url path, query, [:site] req = Net::HTTP::Get.new(url, [:headers]) if block_given? request(req) do |resp| resp.read_body &block end else request(req, nil, [:raw]) end end |
#post(path, query = {}, body = {}, options = {}) ⇒ Object
发送 POST 请求
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/baidu/support/request.rb', line 37 def post(path, query={}, body={}, ={}) uri = build_url path, query, [:site] Util.clean_params(body) if body.select{ |_, v| v.respond_to? :read }.empty? req = Net::HTTP::Post.new uri req.body = (body.empty? ? nil : Util.encode_params(body)) else require 'net/http/post/multipart' body.each { |k, v| body[k] = UploadIO.new v, 'application/octet-stream' if v.respond_to? :read } req = Net::HTTP::Post::Multipart.new uri, body end request req end |