Google Cloud Scheduler-不遵守HTTP标头

时间:2018-11-07 20:46:20

标签: google-cloud-platform google-cloud-scheduler

我正在尝试使用Google Cloud Scheduler向我的应用发送推送:

gcloud beta scheduler jobs create http PUSH --schedule="0 * * * *" --uri="https://fcm.googleapis.com/fcm/send" --description="desc" --headers="Authorization: key=<AUTHKEY> --http-method="POST" --message-body="{\"to\":\"/topics/allDevices\",\"priority\":\"low\",\"data\":{\"success\":\"ok\"}}"    

结果始终为401未经授权。发出命令后:

gcloud beta scheduler jobs describe PUSH

我没有找回这些标题:

description: desc
httpTarget:
  body: eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19  <--- THIS IS WEIRD
  headers:
    Content-Type: application/octet-stream
    User-Agent: Google-Cloud-Scheduler
  httpMethod: POST
  uri: https://fcm.googleapis.com/fcm/send
lastAttemptTime: '2018-11-07T20:32:37.657408Z'
name: projects/..../locations/europe-west1/jobs/PUSH
retryConfig:
  maxBackoffDuration: 3600s
  maxDoublings: 16
  maxRetryDuration: 0s
  minBackoffDuration: 5s
schedule: 0 * * * *
scheduleTime: '2018-11-07T21:00:00.681498Z'
state: ENABLED
status:
  code: 16
timeZone: Etc/UTC
userUpdateTime: '2018-11-07T20:29:15Z'

1 个答案:

答案 0 :(得分:2)

关于身体的第一个问题:

  

body:eyJ0byI6Ii90b3BpY3MvYWxsnByaW9yaXR5IjoRGV2aWNlcyIsIiaGlnaCIsImRhdGEiOnsic3VjY2VzcyI6Im9rIn19   <---这很奇怪

这是的base64编码

  

{\“至\”:\“ / topics / allDevices \”,\“优先级\”:\“低\”,\“数据\”:{\“成功\”:\“确定\”} }

Google正在使用您的--message-body并将其编码为base64

接下来是关于标题的问题。您的'--headers'中有几个错误。

  

-headers =“ Authorization:key = AUTHKEY

您在AUTHKEY之后缺少引号。我将假定此问题只是编辑错误而创建的问题。 (请注意,我无法弄清楚如何在此响应中包含小于和大于字符)。

但是,--headers的语法是错误的。 --headers期望KEY=VALUE,而不是KEY:VALUE。在此示例中,KEYAuthorization,而VALUEkey=AUTHKEY

--headers="Authorization=key=AUTHKEY"