Changing Content-Type to JSON using HTTParty

允我心安 提交于 2019-11-30 17:33:28
superfell

You have to set the Content-Type header to application/json. I haven't used HTTParty, but it looks like you have to do something like

response = (post(Accounts.root_url+"/sobjects/Account/", :body => {:name => "graham"}.to_json) , :options => { :headers => { 'Content-Type' => 'application/json' } } )

I'm somewhat surpised that the format option doesn't do this automatically.

The Content-Type header needs to be set to "application/json". This can be done by inserting :headers => {'Content-Type' => 'application/json'} as a parameter to post, ie:

response = post(Accounts.root_url+"/sobjects/Account/", 
  :body => {:name => "graham"}.to_json,
  :headers => {'Content-Type' => 'application/json'} )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!