What is the origin of the expression going to see a man about a dog?

I thought the expression was going to see a man about a horse. A generic phrase to excuse one's self from present company. Phase used to excuse yourself to go to the restroom.