I remember that at some point on House, M.D., one of the characters mentioned that her patient craved milk because it contained some chemical he/she needed. How does the brain figure out what chemicals it can get from what foods, and by extension what to crave? I know one craves very specific foods, but I eat a lot of foods per meal so I don't see how the body can connect something to its composition.
Check out this question on biology.stackexchange: Do omnivore mammals vary food preferences based on dietary needs?
The answers in that question mention that experiments on Rats and Birds determined that there's an internal chemosensor, the anterior piriform cortex (APC) within bird and rat brains that senses lack of Indispensible Amino Acids (IAA). Animals show aversion to foods that lack IAA in as short as 20-30 minutes.
There's another example listed that mentions that being sodium deficient makes animals like salt more. Their preference for salty taste increases.
I don't know if these findings apply to humans though.