BEIJING — US President Donald Trump went around and over the “Great Firewall” of China in a late-night tweet in Beijing as he thanked his hosts for a rare tour of the Forbidden City and a private dinner at the sprawling, centuries-old palace complex.

Many Western social media platforms such as Twitter and Facebook are banned in China. A sophisticated system has been built to deny online users within China access to blocked content.

That was not an issue for Trump, known for tweeting to his 42.3 million followers at any hour of the day, on Wednesday, the day he arrived in Beijing.

“On behalf of @FLOTUS Melania and I, THANK YOU for an unforgettable afternoon and evening at the Forbidden City in Beijing, President Xi and Madame Peng Liyuan. We are looking forward to rejoining you tomorrow morning!”

Trump even changed his Twitter banner, uploading a photograph of himself and Melania with Chinese President Xi Jinping and his wife, Peng Liyuan, during a Chinese opera performance at the Forbidden City.

The Twitter banner upload did not go unnoticed by Chinese state media, with state broadcaster CCTV flashing screenshots of the photograph Thursday.

Trump’s visit was also the third-most-talked-about topic on Chinese social media platform Weibo over the last 24 hours, trailing only the birthday of a singer in a Chinese boy band and a weekly Asian pop song chart.

Many people wondered how Trump managed to evade China’s tough internet controls.

“I guess he must have done it via wifi on a satellite network,” said a user on Weibo.

Many foreigners log on to virtual private networks (VPNs) to access content hosted outside of China. Another option is to sign up for a data roaming service before leaving one’s home country.

“The president will tweet whatever he wants. That’s his way of communicating directly with the American people. Why not?” a White House official said ahead of Trump’s arrival in Beijing on Wednesday.

Not all of Trump’s tweets in China were bright and cheerful.

“NoKo has interpreted America’s past restraint as weakness,” he tweeted about reclusive North Korea’s nuclear and missile threats. “This would be a fatal miscalculation. Do not underestimate us. AND DO NOT TRY US.”