使用Rails将内容长度添加到API发布请求

时间:2011-09-21 20:26:44

标签: ruby-on-rails json google-maps-api-3 content-length http-1.1

我正在尝试将一些数据发布到Google Places api。但是,当我运行代码(下面)时,我收到411长度要求错误。有谁知道如何使用下面的代码解决这个问题。感谢

require 'rubygems'
require 'httparty'

class Partay
   include HTTParty
  base_uri 'https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key=API_Key' 

end

  #add to google API
   options = {
     :location => {
    :lat => '33.71064',
    :lng => '-84.479605'
  }
    }  
    {
      :accuracy => '50',
  :name=>"Rays NewShoeTree",
  :types=> "shoe_store",
  :language=> "en-AU"
    }

puts Partay.post('/maps/api/place/add/json?sensor=false&key=API_Key', options)

1 个答案:

答案 0 :(得分:0)

您需要在帖子中指定正文。即使只是nil或空哈希,HTTParty也会包含Content-Length头。