A catchphrase made famous by Sesame Street's Cookie Monster*. The explanation of his use of the phrase is not complicated: he is the Cookie Monster. He loves cookies. When he meets people, he asks them to give him a cookie. If they do, this is followed by scenes of ravenous cramming of said cookie(s) into his mouth.
The phrase then started to spread, in the way that memes tend to once they have transmitted themselves into popular culture. It appeared in a program called COOKIE or COOKIE MONSTER written in MIT in 1970 for the DECSYSTEM-20. This program would be installed as a joke on someone's account, and would randomly interrupt their activity with the demand "Give me a cookie!". The only way to get around this repeated demand was to type "cookie" or "A cookie", after which the program would respond with "Mmm. That was tasty." or some similar phrase, and become dormant again. Some people refer to this program as the first known instance of a computer virus, because of the difficulty of detecting the program, though it had no automatic means of transmission, relying on mischievous humans instead.
This was apparently the origin of the use of the word "cookie" to describe a piece of information presented to a remote host on demand, and it has since passed into common parlance.
* - Apparently the phrase may have originated on the Andy Williams show, in his Cookie Bear sketch, which involved a man, dressed up as a bear, asking Andy for cookies repeatedly until Andy ended up screaming at him. Some sources state that the MIT Cookie program refers to Cookie Bear rather than Cookie Monster. Thanks to Wertperch for bringing this to my attention!