简体   繁体   English

发布序列化 Json 正文 - [VERBOSE-2:ui_dart_state.cc(177)] 未处理的异常:错误 -

[英]Post serialised Json body - [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: Error-

I have been stuck for the last 2 days regarding flutter post method with JSON row body, the code which I have tried is shown here.在过去的 2 天里,我一直被困在关于带有 JSON 行主体的 flutter post 方法的问题上,我尝试过的代码显示在此处。

Code 1:代码 1:

void send() async {

    userModel = UserModel(userName: "usernme", password: "password");

       var response = await http.post(
           "https://stagingapi......",
           headers: {"Content-Type": "application/json"},
           body: json.encode(userModel.toJson()));


       print(response.body);
       print(response.statusCode);

}

I have created serialised body Model like,我创建了序列化的身体模型,例如,

import 'package:json_annotation/json_annotation.dart';

part 'UserModel.g.dart';

@JsonSerializable()
class UserModel {
  String userName;
  String password;
  // String xyz;
  UserModel({this.userName, this.password});
  factory UserModel.fromJson(Map<String, dynamic> json) => _$UserModelFromJson(json);
  Map<String, dynamic> toJson() => _$UserModelToJson(this);
}

Code 2:-代码 2:-

Future<User> createUser(String username, String password) async{
  final String apiUrl = "https://stagingapi.....";
  Map<String,String> headers = {'Content-Type':'application/json'};
  final body = jsonEncode({ "userName": username,
    "password": password});
  try {
    var response = await http.post(apiUrl, headers: headers, body: body);
    print(response.statusCode);
    if(response.statusCode == 201){
      final String responseString = response.body;

      return userFromJson(responseString);
    }else{
      return null;
    }
  } catch (error) {
    print('error- $error');
   
    }
  }
}

In both cases or if I try any post code method it throws the following error,在这两种情况下,或者如果我尝试任何邮政编码方法,它都会引发以下错误,

[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: 
#0      IOClient.send (package:http/src/io_client.dart:65:7)
<asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:176:38)
#2      BaseClient.post (package:http/src/base_client.dart:58:7)
#3      post.<anonymous closure> (package:http/http.dart:70:16)
#4      _withClient (package:http/http.dart:166:20)
#5      post (package:http/http.dart:69:5)
#6      _SelectDOBState.send (package:kash_app/SelectDOB.dart:99:29)
#7      _SelectDOBState.initState (package:kash_app/SelectDOB.dart:92:6)
#8      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4812:57)
#9      ComponentElement.mount (package:flutter/src/widgets/framework.dart:4649:5)
#10     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3615:14)
#11     Element.updateChild (package:flutter/src/widgets/framework.dart:3380:18)
#12     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:616<…>

上面的代码在其他 urls 中工作......我已经解决了这个问题,这是我们的后端团队通过configuration in IIS OR secure certificate related添加一些configuration in IIS OR secure certificate related对域 url 进行了一些更改

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter [错误:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:类型“int”不是类型转换中类型“String”的子类型 - Flutter [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'int' is not a subtype of type 'String' in type cast 错误:flutter/lib/ui/ui_dart_state.cc(148) 未处理的异常 - ERROR:flutter/lib/ui/ui_dart_state.cc(148) Unhandled Exception E/flutter (8084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:SocketException:操作系统错误:连接被拒绝 - E/flutter ( 8084): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused webView 在颤振中不起作用 [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] - webView don't work in flutter [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] “[错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:类型&#39;未来<File> &#39; 不是类型“文件?”的子类型在类型转换中“错误 - "[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Future<File>' is not a subtype of type 'File?' in type cast" Error 错误:flutter/runtime/dart_vm_initializer.cc(41)] 未处理的异常:类型“String”不是类型“Map”的子类型<string, dynamic></string,> - ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic> 未处理的异常:“String”类型不是 dart 中“index”错误的“int”类型的子类型 - Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index' error in dart Android未处理的异常错误 - Android unhandled exception error 未处理的异常错误,Android - Unhandled exception error, android 未处理的异常类型错误 - unhandled exception type error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM