[SOLVED] is there a way to check is URL is existing or not in http request?

Issue

This Content is from Stack Overflow. Question asked by Saied Rahimi

is there a way to check is URL is existing or not in http request?
I am working on an accounting app it should sold for many company, so in Sign in page each ueser has to add hes own domain to connect with his company api and data, my question is here if user add worng domain or typing somthing else that is not kind of URL, how can handle it?
is there any way to definde that url is not working or not existing?
and in postman if typing anything insted of url, it say could not sed request. no response no error nothing.
enter image description here



Solution

Just a basic google search

Future _checkUrl(String url) async {
  http.Response _urlResponse =  await http.get(Uri.parse(url));
  if (_urlResponse.statusCode == 200) {
   return true;
  }
  else {
    return false;
  }
}


_checkUrl("https://stackoverf").then((value) => {
  print(value)
});


This Question was asked in StackOverflow by Saied Rahimi and Answered by Atakan Akbulut It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?