Home > other >  Is there any way to convert the response body to XML in flutter?
Is there any way to convert the response body to XML in flutter?

Time:07-31

I have a get request in flutter, the response body comes as json, is there any way to have it in XML? In the Swagger UI it comes as XML but I don't know why it comes as Json in my request. I am using this lines:

final response = await http.get(Uri.parse(selectedURL));
print(response.body);

CodePudding user response:

You probably need to set the Accept header to something like: Accept: application/xml

Something like this might do the trick:

final response = await http.get(
  Uri.parse(selectedURL),
  headers: {
    'Accept': 'application/xml',
  },
);
print(response.body);
  • Related