Home > Enterprise >  Flutter - response.body returning HTML instead of json
Flutter - response.body returning HTML instead of json

Time:11-01

I'm trying to return the json from the api, but html arrives even adding the header specifying application/json. As the image shows, the api works perfectly in Postman.

final response = await http.get(Uri.parse('http://cep.la/avenida paulista'),
      headers: {'Accept': 'application/json'});

enter image description here

enter image description here

https://restninja.io/share/b3949f138446901cc131b04a7acc5983643e43d0/0

CodePudding user response:

you need to call response.body to get the json data

String Json = response.body;

CodePudding user response:

Try this

headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  }
  • Related