I wanted to pass a parameter of type json, but found it was always wrong, so I thought about adding application/json to the header, and tried many times without success. Halfway through, I saw that the default data request type is application/json. But subconsciously ignore it and continue to look for solutions in the wrong direction.
Later, I thought that there might be a problem with the writing of the post method, and it was successfully resolved after searching.
I was so angry at my own stupidity, hey, when encountering a problem, you should first think about whether the direction of solving the problem is correct, and then read more official documents.
Error instance:
Dio dio = new Dio();
response = await dio.post(
'URL',
queryParameters: {
"name": "xiaoming",
"age": "18",
});
print(response);
Correct example 1:
document:
response=await dio.post("/test",data:{
"id":12,"name":"wendu"})
Correct example application 2:
Dio dio = new Dio();
response = await dio.post(
'URL',
data: {
"name": "xiaoming",
"age": "18",
});
print(response);
Correct example 3:
Dio dio = new Dio();
///创建Map 封装参数
Map<String,dynamic> map = Map();
map['name']='xiaoming';
map['age']='18';
response = await dio.post(
'URL',
data: map,
);
print(response);