Changing Content-Type to JSON using HTTParty

后端 未结 2 1140
长发绾君心
长发绾君心 2021-01-04 03:18

I am trying to use Ruby on Rails to communicate with the Salesforce API. I can fetch data easily enough but I am having problems posting data to the server. I am using HTTPa

相关标签:
2条回答
  • 2021-01-04 03:53

    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'} )
    
    0 讨论(0)
  • 2021-01-04 04:07

    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.

    0 讨论(0)
提交回复
热议问题