Below is the HTTP body and header of my JSON. I want to convert it to the expected format of a Postman request where the format is JSON and "raw":
var response = await http.post(
'${UIData.baseAppUrl}/api/v1/endpoint',
body: {
"device_id": "$deviceId",
"country_id": "$countryId",
"contacts": [
{
"name": "test",
"email": "test@test.com",
"phone": "+911111111110"
},
{
"name": "Test 2",
"email": "test2@test2.com",
"phone": "+910000000000"
}
]
},
headers: {
"Accept": "application/json",
"Authorization": "Bearer $token"
},
But when I run this I am getting this error:
type 'List<Map<String, String>>' is not a subtype of type 'String' in type cast
May be in future some one would definitely face this issue for them don't worry
var response = await http.post(
'${UIData.baseAppUrl}/api/v1/endpoint',
body: jsonEncode({
"device_id": "$deviceId",
"country_id": "$countryId",
"contacts": [
{
"name": "test",
"email": "test@test.com",
"phone": "+911111111110"
},
{
"name": "Test 2",
"email": "test2@test2.com",
"phone": "+910000000000"
}
]
}),
headers: {
"Accept": "application/json",
"Authorization": "Bearer $token",
"Content-Type": "application/json",
},
I just use wrap body in jsonEncode()
and use "Content-Type": "application/json"
in header and magic happen.