1

我试图将一些数据发布到Google Places api。但是,当我运行代码(下面)时,我收到一个411长度要求的错误。有谁知道如何使用下面的代码来解决这个问题。谢谢使用Rails将内容长度添加到API发布请求

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) 
+0

我是否缺少url中的一些设置,或者我应该在选项中附加长度哈希值? –

回答

0

您需要在帖子中指定正文。即使只是零或一个空的散列,那么HTTParty将包括Content-Length标头。

相关问题