【发布时间】:2016-05-29 12:36:48
【问题描述】:
法拉第有点挣扎。我想知道我实际发送到服务器的内容。我得到了响应正文,但没有访问请求正文。我发现有一个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>
但我无法接触到身体。有什么想法吗?
谢谢!
【问题讨论】:
-
我也没有看到这样做的好方法,一旦响应返回,创建的 Faraday::Request 对象就是短暂的:\