使用https://requestb.in
,我可以看到webhook正確地發送了header + json正文數據。但是,當我發送json請求到我的服務器時,我得到一個錯誤解析json。從webhook請求解析JSON
我控制器(不能接收體數據):
class ReceiverController < ApplicationController
skip_before_filter :verify_authenticity_token
def handle_post
puts request.headers['Content-Type']
puts "request:"
puts JSON.parse(request.raw_post)
puts "request2:"
puts JSON.parse(request.body.read)
end
end
錯誤輸出:
application/json; charset=utf-8
request:
JSON::ParserError (A JSON text must at least contain two octets!):
app/controllers/receiver_controller.rb:69:in `handle_post'
request2:
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.0ms)
的routes.rb
post "/receive" => 'receiver#handle_post'
說的ouptput'把request.body.read'? –
@Зелёный抱歉,這是'JSON.parse(request.raw_post)'的輸出。我添加了'JSON.parse(request.body.read)'的輸出' – Taylor
您是否閱讀了我的評論?顯示'puts request.body.read'的輸出。 –