首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Flutter中使用http.post并作为String Json对象发送

如何在Flutter中使用http.post并作为String Json对象发送
EN

Stack Overflow用户
提问于 2019-05-15 06:09:11
回答 3查看 563关注 0票数 0

我正在尝试将json对象发送到api端点。但我得到了以下信息:

代码语言:javascript
复制
I / flutter(28184): 200
I / flutter(28184): {"error": "the JSON object must be str, not 'bytes'"}

我尝试过以下几种方法:

代码语言:javascript
复制
Future<http.Response> sendPost() async{
    var post = {
      "profile_id" : "${_profile_id}",
      "profile_name" : "${_profile_Name}",
      "profile_country" : "${_profile_country}",
      "post_id" : "${current_post_id}",
      "post_image_id" : "${current_post_image}",
      "post_desc" : "La La La La La La",
      "post_likes" : "${post_likes}",
      "post_timestamp" : "05-06-2019 22:34",
      "post_comments" : [],
      "post_comments_profile_name" : [],
      "post_comments_profile_image_id" : [],
      "post_comments_timestamp" : []
    };


    var body = utf8.encode(json.encode(post));

    var addPost = await http.post(
      url,
      headers: {"content-type" : "application/json"},
      body: body

      );

      print("${addPost.statusCode}");
      print("${addPost.body}");
      return addPost;
  }

另外,当您回答时,请记住此Map中应该有空数组。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56139284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档