Flutter 如何在颤振post请求中传递Map作为键的值?
代码 Future editResume()异步{ var url='1〕https://example.com",Flutter 如何在颤振post请求中传递Map作为键的值?,flutter,dart,flutter-dependencies,Flutter,Dart,Flutter Dependencies,代码 Future editResume()异步{ var url='1〕https://example.com", String body = jsonEncode({ "resume".toString(): { "id".toString(): 22720456, "name".toString(): "Accounting-Accountant-2020-11-05".toString()
String body = jsonEncode({
"resume".toString(): {
"id".toString(): 22720456,
"name".toString(): "Accounting-Accountant-2020-11-05".toString(),
"years".toString(): 2,
"functional_area_id".toString(): 1,
"sub_functional_area_id".toString(): 1,
"industry_id".toString(): null,
"user_id".toString(): 191451,
"resume_type_id".toString(): 29,
"created_at".toString(): "2020-11-05T11:03:52.846+05:30".toString(),
"updated_at".toString(): "2021-04-27T14:05:09.457+05:30".toString(),
"hide_employer_name".toString(): false,
"hide_educational_marks".toString(): false,
"hide_email".toString(): false
}
});
try {
var dio = Dio();
print(body);
final response = await dio.post(
url,
data: body,
options: Options(
contentType: Headers.jsonContentType,
responseType: ResponseType.json,
),
);
final responseData = json.decode(response.data);
if (responseData["message"] == "All Good") {
throw HttpException('Something went wrong');
} else {
throw HttpException('Something went wrong');
}
} catch (error) {
print(error.toString());
// return error;
}
}
我正在将此代码放入providers.dart文件中,一旦我点击请求,它就会向我提供以下响应:
I/flatter(9781):DioError[DioErrorType.response]:Http状态错误[404]
I/flatter(9781):#0 DioMixin.assureDioError(包:dio/src/dio_mixin.dart:819:20)
I/flatter(9781):#1 DioMixin.(发送请求#文件包:dio/src/dio_mixin.dart:678:13)
I/颤振(9781):
我/弗利特(9781):#2迪奥米辛。拿。。(包装:dio/src/dio_mixin.dart)
I/颤振(9781):
最糟糕的是,如果我在《邮递员》上做了同样的事情,用同样的数据点击请求,我会得到正确/预期的响应