我试图将一些代码从HTTParty
转换为Faraday
。以前我是用:Faraday JSON发布'undefined method bytesize'for have bodies
HTTParty.post("http://localhost/widgets.json", body: { name: "Widget" })
新的片段是:
faraday = Faraday.new(url: "http://localhost") do |config|
config.adapter Faraday.default_adapter
config.request :json
config.response :json
end
faraday.post("/widgets.json", { name: "Widget" })
导致:NoMethodError: undefined method 'bytesize' for {}:Hash
。法拉第能够自动将我的请求主体序列化为字符串吗?
尝试将适配器放在中间件列表中 - 请参阅[高级中间件用法](https://github.com/lostisland/faraday)。 – 2015-04-08 04:19:02
@ l'L'l这绝对是错误。你可以添加一个答案,而不是评论,所以我可以接受+赏金? – 2015-04-10 23:16:36