我正在完成有关设置Cloud Messaging的教程。我按照页面https://firebase.google.com/docs/cloud-messaging/js/client?authuser=0上视频中的说明进行操作 当我尝试发送curl命令时,出现一个奇怪的错误。我已经阅读了Cloud Messaging快速入门以及其他一些尝试解决该错误的页面,但无济于事。
我在命令行上输入的命令是:
curl --header "Authorization: key=AIzaSyCFCmFwwWV53PqV2M-NUZyp6lYSz43tUiQ" --header "Content-Type: application/json" -d '{"to": "di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1", "notification": { "title": "Hello", "body": "World", "icon": "/firebase_logo.png" }}' https://fcm.googleapis.com/fcm/send
结果是:
curl: (3) Port number ended with 'A'
curl: (6) Could not resolve host: notification
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: title
curl: (6) Could not resolve host: Hello,
curl: (6) Could not resolve host: body
curl: (6) Could not resolve host: World,
curl: (6) Could not resolve host: icon
curl: (3) <url> malformed
curl: (3) [globbing] unmatched close brace/bracket in column 1
JSON_PARSING_ERROR: Unexpected character (') at position 0.
答案 0 :(得分:0)
问题出在Windows命令行上。在将单引号替换为双引号并转义内部引号后,其工作原理如下:
curl -X POST -H "Authorization: key=AAAAATYbVMw:APA91bFAEaRl8bZPgWGNGA7BCP22y_OLIlHevfUjEXEEklDav1sOwcxiFiFin625JsdaWJBAF06-U1Ey9-mhz6f2Es9-ztOeXpco6_AkvIbEO4dbe2LnI_JVw-W7mqOT5KeSn23y4b1h" -H "Content-Type: application/json" -d "{\"to\": \"di6GZyDevbI:APA91bFhNMiuJaMIE3IQL2NurPCWBhCtzculj5uvx-on121Z0UczJ0FyiiQbaRFvGqNs3bmq084vQ-z-8vF_GZQ5J-QCBrWgp4_saWSwTXytZmScNbPLGRkOQns_QgETStDTmLJwixI1\", \"notification\": { \"title\": \"Hello\", \"body\": \"World\", \"icon\": \"/firebase_logo.png\" }}" "https://fcm.googleapis.com/fcm/send"
产生预期的结果:
{"multicast_id":5167616001901538265,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1530306327290339%e609af1cf9fd7ecd"}]}