-1

How do I validate a URL before I post a HttpClient.GetAsync call. I want to make sure I am calling a valid URL.

Rasula Caldera
  • 305
  • 1
  • 9
  • Could you please tag your question either [tag:.net] or [tag:.net-core] (not both) and add a tag for the language you are using? Also did you see this possible duplicate for C#/.NET? https://stackoverflow.com/q/924679/397817 – Stephen Kennedy Oct 01 '18 at 13:52

1 Answers1

4

You can use the Uri.TryCreate to validate an URL:

public bool UrlValiator(string url)
{
    Uri validatedUrl;
    return Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out validatedUrl);
}