Home > Enterprise >  how can i convert this Rapid API's HTTP Url to Dart Http request
how can i convert this Rapid API's HTTP Url to Dart Http request

Time:01-24

i have this URL

https://zozor54-whois-lookup-v1.p.rapidapi.com/?rapidapi-key=MYAPIKEYb&domain=DOMAINTOCHECK&format=FORMATTYPE

rapid API gives two header's and other things

I Tried This Code By Exploring HTTP package But Not Working:

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

CodePudding user response:

You need to encode the url with the parameters

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'
});

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

  • Related