Most likely, you would have gotten a prescription for it. Cannabis was popular as a medicine (thanks to William O'Shaughnessy) and cannabis indica was frequently imported into the US from India. Hemp was a big crop in the US. Gieringer notes that smoking marijuana in California was not popular circa 1900. Recreationally, opium parlors and hasheesh dens were popular among the upper classes along East Coast. Marijuana usage was pretty much unregulated so you could just buy it at the pharmacy/get a prescription from your doctor. The Pure Food and Drug Act did not pass until 1906, so cannabis (or any other pharmaceuticals) were not federally regulated prior to this; but some states did pass their own regulatory laws. California passed the first prohibition laws outlawing cannabis in 1913.
Sources: Dale H. Gieringer wrote a good paper about the Cannabis' legal history in California http://www.canorml.org/background/caloriginsmjproh.pdf
United States. Bureau of Chemistry (1905). Bulletin, Issues 96–99. Washington, DC: G.P.O. (pg 22) https://books.google.com/books?id=7KdUAAAAYAAJ&printsec=frontcover&source=gbs_ge_summary_r&cad=0#v=onepage&q=cannabis&f=false
http://www.pbs.org/wgbh/pages/frontline/shows/dope/etc/cron.html
http://query.nytimes.com/mem/archive-free/pdf?res=9E02E3D61539E03ABC4C52DFBF66838F669FDE