ai didi

android - 如何在 Dart 帖子请求中发送数组

转载 作者:行者123 更新时间:2023-12-03 03:40:16 24 4
gpt4 key购买 nike

我尝试使用它们的 registration_ids 向设备组发送消息。

这是我的代码:

List<String> tokens=["token1","token2"];
final url='https://fcm.googleapis.com/fcm/send';
http.post(url,headers:{
"Accept": "application/json",
"Authorization":"key=mykey"
,"project_id":"proID"
},
body:
{
"registration_ids" :tokens ,
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
}
}

当应用程序运行时显示此错误:

Exception has occurred. _CastError (type 'List' is not a subtype of type 'String' in type cast)

如何解决?

最佳答案

问题解决了;我刚刚对正文进行了编码:

List<String> tokens=["token1","token2"];
final url='https://fcm.googleapis.com/fcm/send';
http.post(url,headers:{
"Accept": "application/json",
"Authorization":"key=mykey"
,"project_id":"proID"
},
body:json.encode(
{
"registration_ids" :tokens ,
"collapse_key" : "type_a",
"notification" : {
"body" : "Body of Your Notification",
"title": "Title of Your Notification"
}
)
}

关于android - 如何在 Dart 帖子请求中发送数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57017135/

24 4 0
文章推荐: gradle - 如何使用Gradle配置MarkLogic数据库备份?
文章推荐: sorting - 如何在Dart中创建排序方法?
文章推荐: gradle - 使用mysql-connector时buildscript中的ClassNotFoundException
文章推荐: flutter - 在Flutter网站中上传图片
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com