0

我必须从此 api 获取数据 - https://api.wazirx.com/api/v2/market-status 我收到“xmlhttprequest 错误”

我应该如何克服这一点。

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");
  }
}
4

1 回答 1

0

尝试这个。添加标题“接受”:“应用程序/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");
  }
}
于 2021-03-22T18:48:39.853 回答