1
用法拉第掙扎了一下。我想知道我實際發送給服務器的內容。我得到響應主體,但不訪問請求主體。我發現有一個request.env
方法,但我無法以某種方式訪問該機構。法拉第獲得訪問請求參數
這將如何工作?
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
data = conn.post do |req|
req.url '/nigiri'
req.headers['Content-Type'] = 'application/json'
req.body = '{ "name": "Unagi" }'
end
# how do I get access to the request body here?
我想這樣做是這樣的:
[4] pry(main)> request.env.request
=> #<struct Faraday::RequestOptions
params_encoder=nil,
proxy=nil,
bind=nil,
timeout=nil,
open_timeout=nil,
boundary=nil,
oauth=nil>
但我對身體有沒有訪問。有任何想法嗎?
謝謝!
我沒有看到一個很好的方式做這一點,時生成法拉第:: Request對象是短暫的,一旦反應回來:\ – Anthony