Calculate content-length correctly to support variable-width encoding

Make sure that multi byte characters are properly accounted for when sending data e.g. JSON objects with international strings