They didn't really have a choice? The Chinese had huge armies, but were using Middle Ages tactics against European powers using the latest in 19th century hardware and tactics.
Look at the numbers: in the First Opium War, the Brits had 19,000 troops vs. 200,000 for the Chinese. But by the end of the war, only 521 British soldiers had been killed or wounded, vs. 18,000–20,000 Chinese soldiers killed or wounded. That's staggering. And the Europeans probably could have taken the entire country if they'd wished... but they were more interested in commerce than conquest, and in any event they didn't have enough troops to hold the country. So they were perfectly happy taking "free trade zones" in port cities, or nearby islands instead.