Flutter 我如何创建和维护一个带有颤振的会话

Flutter 我如何创建和维护一个带有颤振的会话,flutter,dart,Flutter,Dart,我有一个问题: 我使用http包为一个json文件创建了两个http调用。 第一个调用是post调用,我在其中创建产品: Future<http.Response> AddPro(String title) async { final response = await http.post( 'jsonurl', headers: <String, String>{ 'Content-Type': 'application/json',

我有一个问题:

我使用http包为一个json文件创建了两个http调用。 第一个调用是post调用,我在其中创建产品:

Future<http.Response> AddPro(String title) async {
  final response = await http.post(
    'jsonurl',
    headers: <String, String>{
     'Content-Type': 'application/json',
    },
    body: jsonEncode(<String, String>{
      "title": title,
    }),
);
return response;}
Future<List<ListC>> fetchListC(http.Client client) async {
  final response =
      await http.get('jsonurl');
  return compute(parseListC, response.body);
}

List<ListC> parseListC(String responseBody) {
  final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>();
  return parsed.map<ListC>((json) => ListC.fromJson(json)).toList();
}
Future AddPro(字符串标题)异步{
最终响应=等待http.post(
“jsonurl”,
标题:{
“内容类型”:“应用程序/json”,
},
正文:JSONECODE({
“头衔”:头衔,
}),
);
返回响应;}
第二个调用是get调用,我在其中创建了产品:

Future<http.Response> AddPro(String title) async {
  final response = await http.post(
    'jsonurl',
    headers: <String, String>{
     'Content-Type': 'application/json',
    },
    body: jsonEncode(<String, String>{
      "title": title,
    }),
);
return response;}
Future<List<ListC>> fetchListC(http.Client client) async {
  final response =
      await http.get('jsonurl');
  return compute(parseListC, response.body);
}

List<ListC> parseListC(String responseBody) {
  final parsed = jsonDecode(responseBody).cast<Map<String, dynamic>>();
  return parsed.map<ListC>((json) => ListC.fromJson(json)).toList();
}
Future fetchListC(http.Client)异步{
最后答复=
等待http.get('jsonurl');
返回compute(parseListC,response.body);
}
列表parseListC(字符串响应库){
final parsed=jsonDecode(responseBody.cast();
返回parsed.map((json)=>ListC.fromJson(json)).toList();
}
问题是第二个调用get调用不能正常工作,因为在它的响应中,没有在post调用中创建的产品。 会话id(??)可能有问题,如何为每个调用创建和维护相同的会话

我的错误是:

I/flutter (15399): Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.     
I/flutter (15399): Receiver: _LinkedHashMap len:6
I/flutter (15399): Tried calling: cast<Map<String, dynamic>>()
I/flutter (15399): Found: cast<RK, RV>() => Map<RK, RV>
I/flatter(15399):异常:NoSuchMethodError:类“\u InternalLinkedHashMap”没有具有匹配参数的实例方法“cast”。
I/颤振(15399):接收器:_LinkedHashMapLen:6
I/flatter(15399):尝试调用:cast()
I/颤振(15399):找到:cast()=>Map
只有当我通过POST调用来创建产品,并通过GET调用来获取产品时,我才会遇到这个问题。。。这就好像弗利特记不起创建的产品。。。因为有了邮递员,一切都正常


可能它们有不同的标题?

您的json url正在工作?应该与“会话”无关。您发布到的URL,它在哪里保留数据?@OldProgrammer它是WooCommerce Rest Api。。。一切都很好postman@dm_tr是的,我的json url正在工作。。。我试着和邮递员一起接电话和投递电话,效果很好。。。在颤振代码中,post呼叫回复状态代码为201…因此它工作正常。。。但是我不能用get调用获取数据(只在flutter中),我不知道为什么…你确定你的get请求和postman的头都是一样的吗?也许可以试着运行fiddler来查看您的json url正在工作的实际HTTP数据流?应该与“会话”无关。您发布到的URL,它在哪里保留数据?@OldProgrammer它是WooCommerce Rest Api。。。一切都很好postman@dm_tr是的,我的json url正在工作。。。我试着和邮递员一起接电话和投递电话,效果很好。。。在颤振代码中,post呼叫回复状态代码为201…因此它工作正常。。。但是我不能用get调用获取数据(只在flutter中),我不知道为什么…你确定你的get请求和postman的头都是一样的吗?也许可以尝试运行fiddler来查看实际的HTTP数据流