Just wanted to say thank you for this – I had almost exactly the same requirement when using a PUT request to send JSON to a server that also used an OAuth2 token in an Authorization header. Neat code.