-1

I am trying to read data from this link to check domain availability :

private bool DomainAvailble(string domain)
        {
            string response = "";
            StreamReader objReader;
            string sURL;
            sURL = "https://testapi.internet.bs/Domain/Check?ApiKey=testapi&Password=testpass&Domain=" + domain;
            WebRequest wrGETURL;
            wrGETURL = WebRequest.Create(sURL);
            try
            {
                Stream objStream;
                objStream = wrGETURL.GetResponse().GetResponseStream();
                objReader = new StreamReader(objStream);
                response = objReader.ReadToEnd();
                objReader.Close();
                objReader.Dispose();
            }
            catch (Exception ex)
            {
                ex.ToString();
            }

            var test = response.ToArray();

            if (ContainsInvariant(response, "nstatus=AVAILABLE"))
                return true;
            else
                return false;
        }

        private bool ContainsInvariant(string sourceString, string filter)
        {
            return sourceString.ToLowerInvariant().Contains(filter);
        }

but this code is not working, but i can read the result as :

transactid=860d5feb048352ae25b8bd4134a4910b\nstatus=UNAVAILABLE\ndomain=common.com\nminregperiod=1Y\nmaxregperiod=10Y\nregistrarlockallowed=YES\nprivatewhoisallowed=YES\nrealtimeregistration=YES

What is the way to read the status of whether a domain is available or not on this result, and is there a way where I can read each value?

DWright
  • 9,258
  • 4
  • 36
  • 53
Ahmad Alaa
  • 767
  • 9
  • 30
  • Please make sure to step through your code at least once using debugger so you can either narrow down the issue or even solve it yourself. For future questions avoid "but this code is not working," - instead provide exact errors or expected/observed behavior. – Alexei Levenkov Apr 27 '15 at 00:47

1 Answers1

1

Your ContainsInvariant function has a bug. It's not forcing the filter to be lowercase. You may want to look at this SO question for better ways to do a case-insensitive Contains.

As far as reading each value, just use the String.Split method to split it up on the "\n" newline characters which will give you an array for each key/value pair. You can then further split each of those pairs on the "=" equals sign to get the key and value separately.

Community
  • 1
  • 1
David Archer
  • 2,121
  • 1
  • 15
  • 26