Firebase 正在尝试将JSON HTTP post转换为CFHTTP post

Firebase 正在尝试将JSON HTTP post转换为CFHTTP post,firebase,coldfusion,firebase-cloud-messaging,cfml,cfhttp,Firebase,Coldfusion,Firebase Cloud Messaging,Cfml,Cfhttp,通过重新创建Firebase控制台成功发布的输出,我试图通过CFHTTP正确地编写对Firebase Cloud Messaging REST API的调用。下面是控制台声明的正确代码 POST /fcm/send HTTP/1.1 Host: fcm.googleapis.com Content-Type: application/json Authorization: key=AIzcXE cache-control: no-cache { "to": "e5kpn8h9bR95

通过重新创建Firebase控制台成功发布的输出,我试图通过CFHTTP正确地编写对Firebase Cloud Messaging REST API的调用。下面是控制台声明的正确代码

POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Content-Type: application/json
Authorization: key=AIzcXE
cache-control: no-cache

{   
  "to": "e5kpn8h9bR95NuXVHTOi50bCURG0BS4S6ccUm3X5q",
  "priority": "high",
  "notification" : {
    "title": "",
    "body" : "This is the actual message content",
    "sound": "default", 
    "image": "https://gladevalleyanimalhospital.net/wp-content/uploads/2017/03/raster-7.png"
  }
} 
这是我们当前的CFHTTP代码:

<cfhttp method="Post" url="https://fcm.googleapis.com/fcm/send"> 
   <cfhttpparam type="header" name="Authorization" value="key=AIzXE">
   <cfhttpparam type="header" name="Content-Type" value="application/json">
   <cfhttpparam type="header" name="Postman-Token" value="e19b8abf3f9">
   <cfhttpparam type="header" name="cache-control" value="no-cache">

   <cfhttpparam type="Formfield" value="3569D24982E3B" name="to"> 
   <cfhttpparam type="Formfield" value="high" name="priority"> 
   <cfhttpparam type="Formfield" value="Test" name="title">
   <cfhttpparam type="Formfield" value="This is the actual message content" name="body"> 
   <cfhttpparam type="Formfield" value="https://gladevalleyanimalhospital.net/wp-content/uploads/2017/03/raster-7.png" name="image"> 
</cfhttp>
处理formfields时似乎会出现问题。我得到了下面的错误,这是在处理第一个要处理的formfield时发生的

JSON_分析_错误:位置0处出现意外字符t


任何帮助都将不胜感激。谢谢你

API期望一个JSON字符串作为请求主体,但代码将所有值作为表单字段单独提交。去掉所有formfield参数,并使用适当的键和值构建单个结构:

<cfset bodyData = {  "to": "***the_message_recipient_id_here****",
                     "priority": "high",
                     "notification" : {
                       "title": "",
                       "body" : "This is the actual message content",
                       "sound": "default", 
                       "image": "https://example.com/someimage-name.png"
                      }
                } >

API期望一个JSON字符串作为请求体,但代码将所有值作为表单字段单独提交。去掉所有formfield参数,并使用适当的键和值构建单个结构:

<cfset bodyData = {  "to": "***the_message_recipient_id_here****",
                     "priority": "high",
                     "notification" : {
                       "title": "",
                       "body" : "This is the actual message content",
                       "sound": "default", 
                       "image": "https://example.com/someimage-name.png"
                      }
                } >

这篇文章可能会有帮助:这篇文章可能会有帮助:很高兴它成功了。很高兴它成功了。