HTTParty 和 Urban Airship 的 400 错误请求
我有一个应用程序,需要在将符合特定条件的帖子放入数据库时向用户发送推送通知。如果满足条件,我正在使用城市飞艇和 HTTParty 发出必要的请求。我的模型如下:
class Urbanairship
include HTTParty
base_uri 'https://go.urbanairship.com'
headers "Content-Type" => "application/json"
basic_auth "xxxappkeyxxx", "xxxappsecretxxx"
default_params :output => 'json'
format :json
def self.push(badge, alert_message, token)
self.post('/api/push/',:body => {:aps => {:badge => badge, :alert => alert_message}, :device_tokens => [token]})
end
end
当我在控制台中测试时,我不断收到 400 bad request。关于问题是什么有什么想法吗?我知道城市飞艇在请求标头中需要“content-type:application/json”,但这应该包含在模型中。提前致谢, 杰克
I have an app that requires push notifications sent to user when a post matching certain criteria is put onto the db. I am using urban airship and HTTParty to make the necessary requests if the conditions are met. My model is as follows:
class Urbanairship
include HTTParty
base_uri 'https://go.urbanairship.com'
headers "Content-Type" => "application/json"
basic_auth "xxxappkeyxxx", "xxxappsecretxxx"
default_params :output => 'json'
format :json
def self.push(badge, alert_message, token)
self.post('/api/push/',:body => {:aps => {:badge => badge, :alert => alert_message}, :device_tokens => [token]})
end
end
I keep getting a 400 bad request when I test this in the console. Any ideas as to what the problem is? I know that urban airship needs a 'content-type:application/json' in the request header, but that should be covered in the model. Thanks in advance,
Jack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己并不了解 HTTParty,但如果您能够内省结果并获得实际的响应正文,那应该会告诉您更多信息。正如您所提到的,400 可能来自丢失的内容类型或无效的 JSON,但它也可能来自无效的设备令牌或徽章编号。
I don't know HTTParty myself, but the most if you can introspect the result and get the actual response body, that should tell you more. A 400 could be from the missing content-type, as you mentioned, or invalid JSON, but it could also be from a an invalid device token or badge number.