This was a big confusion at the very beginning for me, too. My very first sentence, learning from “Pimsleur Mandarin 1,” was 我会说一点儿普通话. Then people in Shanghai looked at me funny, and said, “中文.” I then visited a friend in the north, and I tried to say 我会说一点儿中文, and everyone corrected me: 汉语. I then spent time in my girlfriend’s native Fujian, and people would whisper to her, “他会说普通话吗？”
From a technical standpoint, each of those terms means something different. But in everyday life, different regions tend to use different terms interchangeably. (And native speakers - please let me know if I got something wrong here!)
中文, technically, is the written language of China. That means anyone who speaks anything that is tied to the Chinese script, including Cantonese and other dialects, is technically speaking “中文.” (Notice my over-use of the word “technically”!)
汉语, technically, is the spoken language of the ethnic majority - the 汉族 (in contrast to, for example, the Mongolians). China is made up of over 50 ethnic groups, and the 汉 are by far the largest. Again, technically, this could be any of the spoken languages that are tied to the script invented by the ethnic majority - 汉字. Technically, this would include dialects like Cantonese.
普通话, technically (and in this case, it’s always used in its technical sense), is the government-approved pronunciation. In other words: the 4-toned Mandarin we’re all learning. It specifically excludes Cantonese, Shanghainese, the obscure dialect spoken by my wife’s family in the mountains of Fujian, and all others.
国语 I’ve encountered far less - only around people from Taiwan. It means the same thing as 普通话: The nationally-approved way of speaking, in contrast to local dialects.
The confusion around these terms is that, from a Westerner’s perspective, “Chinese” is not a language; it’s a huge group of languages that are tied together by a non-phonetic script (汉字). Within the country of China, there are also minority languages that are not tied to that script. Add to this all kinds of not-allowed-to-be-spoken tensions among those people groups, and you’ve got a recipe for real confusion about terminology.