如何将此Rapid API HTTP URL转换为Dart Http请求

nlejzf6q  于 2023-01-28  发布在  其他
关注(0)|答案(1)|浏览(87)

我有此URL
https://zozor54-whois-lookup-v1.p.rapidapi.com/?rapidapi-key=MYAPIKEYb&domain=DOMAINTOCHECK&format=FORMATTYPE
快速API提供两个标头和其他内容
我尝试了此代码通过探索HTTP包但不工作:

import 'package:http/http.dart' as http;

void main() async {
  var url = 'https://zozor54-whois-lookup-v1.p.rapidapi.com/?domain=sendrank.com&format=json';
  var headers = {
    'X-Rapidapi-Key': APIKEyY
    'X-Rapidapi-Host': 'zozor54-whois-lookup-v1.p.rapidapi.com',
    'Host': 'zozor54-whois-lookup-v1.p.rapidapi.com'
  };

  var response = await http.get(url, headers: headers);
  print(response.body);
}
jpfvwuh4

jpfvwuh41#

您需要使用参数对url进行编码

final queryParameters = {
  'domain': 'sendrank.com',
  'format': 'json',
};

final uri = Uri.https('zozor54-whois-lookup-v1.p.rapidapi.com', '/', queryParameters);

final response = await http.get(uri, headers: {
 'X-Rapidapi-Key': APIKEyY
    'X-Rapidapi-Host': 'zozor54-whois-lookup-v1.p.rapidapi.com',
    'Host': 'zozor54-whois-lookup-v1.p.rapidapi.com'
});

参见How do you add query parameters to a Dart http request?

相关问题