Changing Content-Type to JSON using HTTParty

后端 未结 2 1139
长发绾君心
长发绾君心 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'} )
    

提交回复
热议问题