The root cause is WiFiClient::write does not handle partial send. The same code works on ESP8266. The PR is here #503.