<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          FaradayRuby的HTTP 客戶端

          聯(lián)合創(chuàng)作 · 2023-09-29 09:26

          Faraday 是一個Ruby 的HTTP 客戶端開發(fā)庫,提供了一個通用的接口,支持如下適配器:

          示例代碼:

          conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
            faraday.request  :url_encoded             # form-encode POST params
            faraday.response :logger                  # log requests to STDOUT
            faraday.adapter  Faraday.default_adapter  # make requests with Net::HTTP
          end
          
          # set proxy with string
          conn.options.proxy = "http://user:[email protected]/"
          
          # set proxy with hash
          conn.options.proxy = { :uri => 'http://user:passwordexample.org' }
          
          # specify proxy user/pass
          conn.options.proxy = { :uri => 'http://user:pass.org',
            :user => 'user',
            :password => 'pass' }
          
          ## GET ##
          
          response = conn.get '/nigiri/sake.json'     # GET http://sushi.com/nigiri/sake.json
          response.body
          
          conn.get '/nigiri', { :name => 'Maguro' }   # GET /nigiri?name=Maguro
          
          conn.get do |req|                           # GET http://sushi.com/search?page=2&limit=100
            req.url '/search', :page => 2
            req.params['limit'] = 100
          end
          
          ## POST ##
          
          conn.post '/nigiri', { :name => 'Maguro' }  # POST "name=maguro" to http://sushi.com/nigiri
          
          # post payload as JSON instead of "www-form-urlencoded" encoding:
          conn.post do |req|
            req.url '/nigiri'
            req.headers['Content-Type'] = 'application/json'
            req.body = '{ "name": "Unagi" }'
          end
          
          ## Per-request options ##
          
          conn.get do |req|
            req.url '/search'
            req.options.timeout = 5           # open/read timeout in seconds
            req.options.open_timeout = 2      # connection open timeout in seconds
          
            # set proxy with string
            req.options.proxy = "http://user:[email protected]/"
          
            # set proxy with hash
            req.options.proxy = { :uri => 'http://user:passwordexample.org' }
          
            # specify proxy user/pass
            req.options.proxy = { :uri => 'http://user:pass.org',
              :user => 'user',
              :password => 'pass' }
          end
          瀏覽 24
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美性受XXXX黑人XYX | 国产精品高潮无套内谢 | 亚洲黄色视频在线观看网站 | 囯产精品宾馆在线精品酒店 | 欧美日韩大片网 |