中文 literally means languages spoken by Chinese people, which in theory includes other languages spoken by ehnic minorities in China such as Tibetan language, Mongolian languages and so on.
汉语 literally means languages spoken by Han (most people in Chinese are Han).
In fact, 中文 and 汉语 are the same. But 汉语 tends to be more accurate in describing Chinese language. I my self perfer to say 汉语 instead of 中文 when communicating with foreign friends.