This simple static class contains a static method called sOnline that accepts a username as a string param. it make a call to an old yahoo api that will determine if a Y! user is online. This only returns true if the user is not using stealth, this will return false if a user is online but "invisible"

I'm not sure what enticed me to write this class. but I guess it was a fun 4 minutes anyway. :) hope someone finds use for it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace YahooIM_User_Online_Check
{
    public static class YimIsOnline
    {
        /// <summary>
        /// Returns the state of a Yahoo IM user assuming user's are not using stealth settings.
        /// </summary>
        /// <param name="Username">Yahoo user name, should not include "@Yahoo.com"</param>
        /// <returns></returns>
        public static bool isOnline(string Username)
        {
            string isonval = PostData("http://mail.opi.yahoo.com/online?u=" + Username.Trim() + "&m=t&t=1");

            if (isonval == "00")
            {
                return false;
            }
            else if (isonval == "01")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private static string PostData(string url)
        {
            HttpWebRequest request = null;

                Uri uri = new Uri(url);
                request = (HttpWebRequest)WebRequest.Create(uri);
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
   
            string result = "";

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
                    {
                        result = readStream.ReadToEnd();
                    }
                }
            }
            return result;
        }
    }
}

It's not working when I check myself--always enters if (isonval == "00") . My profile is not hidden. Is there another setting I need to check?

for some reason, if you are logged on with the web messenger, or if you have any status other than the default available it shows false.

just paste

"http://mail.opi.yahoo.com/online?u=yourusername&m=t&t=1"

into a webbrowser and it will either show 01 or 00 on the screen, My class just checks for that.

also keep in mind that it should be the userID without the @yahoo.com

I used it when I had dial up internet to quickly check if my girlfriend was online as yahoo messenger often failed to connect. It was about 90% accurate, but that api is as simple as it could be, it was originally created so web designers or bloggers could easily have their website indicate if they were available on the messenger.

Yeah, I tried some other code with basically the same post data and the result was the same (said not online though I was), yet more verbose...

I started looking into Yahoo API's, but got sidetracked while trying to narrow down this particular function/interface...

hello
how i can know that id is invisible
this code show me only online/offline
now how i can do that for invisible?

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.