HTTParty 和 Urban Airship 的 400 错误请求

发布于 2024-11-05 22:20:05 字数 646 浏览 1 评论 0原文

我有一个应用程序,需要在将符合特定条件的帖子放入数据库时​​向用户发送推送通知。如果满足条件,我正在使用城市飞艇和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2024-11-12 22:20:05

我自己并不了解 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文