0

I have to fetch data from this api - https://api.wazirx.com/api/v2/market-status I am getting "xmlhttprequest error"

how should I overcome this.

Future<void> fetchUserData() async {
  final response = await http.get(Uri.https('api.wazirx.com', '/api/v2/market-status'));
  
  if (response.statusCode == 200) {
    print(response.body);
  } else {
    throw Exception("Request Rejected");
  }
}

1 Answers1

0

Try this. add the headers 'Accept' : 'application/json'


Future<void> fetchUserData() async {
  final host = 'api.wazirx.com';
  final path = '/api/v2/market-status'; 
  final headers = {'Accept': 'application/json'};
  final uri = Uri.https(host, path);
  final response = await http.get(uri, headers: headers);
  if (response.statusCode == 200) {
    print(response.body);
  } else {
    throw Exception("Request Rejected");
  }
}
alabiboo
  • 53
  • 1
  • 10