Monday, January 05, 2009

Connecting and reading run data from NikePlus in C#

There's already quite a few posts and examples out there in the blogosphere for how to read data from NikePlus, so I won't explain this in great detail.

But in case anyone is interested, then here's my first stab at some code to do it:

            CookieContainer cookies = new CookieContainer();


            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(


                "your user name here",

                "your password here"));

            request.CookieContainer = cookies;


            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())


                Stream s = response.GetResponseStream();

                StreamReader reader = new StreamReader(s);

                string text = reader.ReadToEnd();




            HttpWebRequest requestRunList = (HttpWebRequest)WebRequest.Create(


            requestRunList.CookieContainer = cookies;


            using (HttpWebResponse responseRunList = (HttpWebResponse)requestRunList.GetResponse())


                Stream s = responseRunList.GetResponseStream();

                StreamReader reader = new StreamReader(s);

                string text = reader.ReadToEnd();




            HttpWebRequest requestRun = (HttpWebRequest)WebRequest.Create(string.Format(


                "pick a run from the run list retrieved above"


            requestRun.CookieContainer = cookies;


            using (HttpWebResponse responseRun = (HttpWebResponse)requestRun.GetResponse())


                Stream s = responseRun.GetResponseStream();

                StreamReader reader = new StreamReader(s);


                XmlSerializer xmlS = new XmlSerializer(typeof(plusService));               

                plusService plusService = (plusService)xmlS.Deserialize(reader);


                Debug.WriteLine("status = " + plusService.status);

                Debug.WriteLine("datatype = " + plusService.sportsData.extendedDataList.extendedData.dataType);

                Debug.WriteLine("intervaltype = " + plusService.sportsData.extendedDataList.extendedData.intervalType);

                Debug.WriteLine("intervalUnit = " + plusService.sportsData.extendedDataList.extendedData.intervalUnit);

                Debug.WriteLine("intervalValue = " + plusService.sportsData.extendedDataList.extendedData.intervalValue);

                string[] items = plusService.sportsData.extendedDataList.extendedData.Value.Split(',');

                foreach (string item in items)

                    Debug.WriteLine("\t" + item);              




Where plusService is a class generated using "xsd.exe /classes" on an .xsd file generated from some example xml.

Note: maybe I should explain and expand upon this a bit better - I will when I tidy up the code a bit!


  1. this is very nice site and content mentioned abover are very informatic.
    It provider

  2. this is one of the most informative and useful site
    IT trends

  3. The blog is marvelous and enthusiastic.First time i visit your blog and love it.I ll also tell my

    friends to visit your blog and read it........................

    Software Solution

  4. Definately it is a very beneficial for the developers.. I to benefinted a lot using this...... No doubt,it is an useful site and an informative one.....
    I really appreciate the entire team related to this...

    IT Solution