我想将 Routific API 集成到 Rails 应用程序中。我使用 HTTParty 发出请求,但收到以下消息 {"error"=>"Expecting JSON data in the body"}
我不明白...我正在正文中发送 json。请检查下面我的代码。
感谢您的帮助
朱利安
file = File.read("#{Rails.root}/app/controllers/demo.json")
api_key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI1ODE3M2ZiNTk1NzRjZTFiMmZhNWEwNTAiLCJpYXQiOjE0Nzc5MTg2NDZ9.extq0nKtPGwj6VXxMpj9u8uapasKVSorWeTBFW7HgOE"
headers = {
"Content-Type:" => "application/json",
'authorization'=> 'bearer ' + api_key
}
@results = HTTParty.post("https://api.routific.com/v1/vrp",
:headers => headers,
:body => file.to_json)
最佳答案
您添加了无效 header
它应该是“Content-Type”而不是“Content-Type:”(不带冒号)
关于ruby-on-rails - Rails + HTTParty : Expecting JSON data in the body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40351794/