简体   繁体   English

使用HTTParty和Urban Airship的400错误请求

[英]400 Bad Request with HTTParty and Urban Airship

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. 如果满足条件,我将使用城市飞艇和HTTParty发出必要的请求。 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. 在控制台中测试此错误消息时,我总是收到400错误的请求。 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. 我知道市区的飞艇在请求标头中需要一个“ content-type:application / json”,但这应该包含在模型中。 Thanks in advance, Jack 预先感谢,杰克

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. 我本人并不了解HTTParty,但是如果您可以内省结果并获得实际的响应正文,则最多的还是应该告诉您更多信息。 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. 如前所述,400可能来自缺少的内容类型,或者来自无效的JSON,但也可能来自无效的设备令牌或徽章编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM