public async Task <bool> IsValidDomain(string url)
        {
            url = DomainValidations.StripProtocol(url);
            url = DomainValidations.StripUri(url);

            // Get response
            var message = await _client.GetAsync($"https://dns.google.com/resolve?name={url}&type=A");

            if (!message.IsSuccessStatusCode)
            {
                return(false);
            }

            var content = await message.Content.ReadAsStringAsync();

            var response = JsonSerializer.Deserialize <Dictionary <string, JsonElement> >(content);

            // Parse response
            if (response.TryGetValue("Status", out var value))
            {
                return(value.GetInt32() == 0);
            }

            // Not valid
            return(false);
        }
Exemplo n.º 2
0
 public void StripUriReturnsDomainWhenUriNotPresent()
 {
     Assert.Equal(DomainWithoutUri, DomainValidations.StripUri(DomainWithoutUri));
 }