I agree with moondog. Both cities are vibrant and exciting, but Beijing demands more time simply because it seems to have far more in the way of sites. With two nights in Shanghai you'll of course have only scratched the surface, but you'll at least have a good sense for the feel of the city. With two nights in Beijing you basically only have time for the Great Wall and the Forbidden City, and there is much more in Beijing besides.
Hangzhou is a good suggestion. If you have time, you might also want to try Nanjing, which is two hours from Shanghai and was the Ming Dynasty (and Nationalist) capital.