使用 Rails 将内容长度添加到 API post 请求
我正在尝试将一些数据发布到 Google Places api。但是,当我运行代码(如下)时,我收到 411 Length required 错误。有谁知道如何使用下面的代码解决这个问题。谢谢
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)
I'm trying to post some data to the Google Places api. However when I run the code (below) I receive a 411 Length Required error. Does anyone know how to resolve this using the code below. Thanks
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在帖子中指定正文。即使只是 nil 或空哈希,HTTParty 也会包含 Content-Length 标头。
You need to specify a body in the post. Even just nil or an empty hash, then HTTParty will include the Content-Length header.