Flutter flatter:http.post对象

Flutter flatter:http.post对象,flutter,dart,Flutter,Dart,我正在尝试发送带有多个变量的http.post请求 var acc = { 'acc_type': 'normal', 'time': 'Jan 27', }; var what = await http.post( 'http://localhost:7200/api/activity/addactivity', headers: <String, String>{ 'Content-Type': 'application/js

我正在尝试发送带有多个变量的http.post请求

var acc = {
    'acc_type': 'normal',
    'time': 'Jan 27',
  };

  var what = await http.post(
    'http://localhost:7200/api/activity/addactivity',
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(
      <String, dynamic>{
        'userId': 'aaa111',
        'location': 'hellooooo',
        'acc': acc
      },
    ),
  );
var acc={
“acc_类型”:“正常”,
“时间”:“1月27日”,
};
var what=等待http.post(
'http://localhost:7200/api/activity/addactivity',
标题:{
“内容类型”:“应用程序/json;字符集=UTF-8”,
},
正文:JSONECODE(
{
“userId”:“aaa111”,
“地点”:“你好”,
“acc”:acc
},
),
);
当我删除
acc:acc
时,颤振发送请求。但是,我需要将
var acc
值发送到服务器以发布它。我试图通过
http.post()
函数将其编码为JSON。它似乎不起作用。如何将对象作为
post请求的一部分发送?

这将起作用

import 'dart:convert';

//....

var what = await http.post(
 'http://localhost:7200/api/activity/addactivity',
  headers: <String, String>{
    'Content-Type': 'application/json; charset=UTF-8',
  },
  body: json.encode(
    <String, dynamic>{
      'userId': 'aaa111',
      'location': 'hellooooo',
      'acc': acc
    },
  ),
);
导入'dart:convert';
//....
var what=等待http.post(
'http://localhost:7200/api/activity/addactivity',
标题:{
“内容类型”:“应用程序/json;字符集=UTF-8”,
},
正文:json.encode(
{
“userId”:“aaa111”,
“地点”:“你好”,
“acc”:acc
},
),
);

尝试使用acc参数发送请求时出现了什么错误?因此,我尝试打印错误,但没有看到任何错误。我在请求的开头和结尾设置了
print()
方法。只有开头的那一张打印出来。此外,每当我收到请求时,我都会将服务器上的
console.log()
设置为console.log。它没有记录任何东西。如果我发送请求时没有
acc:acc
,则它会正常记录和请求。我看到正在打印所有的console.log和print方法。